Search in sources :

Example 36 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformats-binary by FasterXML.

the class ParseIncompleteArray240Test method testIncompleteFixedSizeObject.

// And might as well do the same for Objects too
public void testIncompleteFixedSizeObject() throws Exception {
    final byte[] input = { (byte) 0xA3 };
    try (CBORParser p = cborParser(F, input)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        try {
            p.nextToken();
            fail("Should NOT pass");
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input in Object value: expected 3 more");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 37 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString236TruncatedString.

// Variant where the length itself exceeds buffer
public void testShortString236TruncatedString() throws Exception {
    // String with length of 6 bytes claimed; only 5 provided
    final byte[] input = { 0x63, 0x41, 0x2d };
    try (CBORParser p = cborParser(input)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input in VALUE_STRING");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 38 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString236EndsWithPartialUTF8.

// Variant where the length would be valid, but the last byte is partial UTF-8
// code point
public void testShortString236EndsWithPartialUTF8() throws Exception {
    final byte[] input = { 0x63, 0x41, 0x2d, (byte) 0xda };
    try (CBORParser p = cborParser(input)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Malformed UTF-8 character at the end of");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 39 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString237InvalidTextValue.

public void testShortString237InvalidTextValue() throws Exception {
    // String with length of 2 bytes, but a few null bytes as fillers to
    // avoid buffer boundary
    // (2nd byte implies 2-byte sequence but 3rd byte does not have high-bit set)
    byte[] input2 = { 0x62, (byte) 0xCF, 0x2d, 0, 0, 0, 0, 0, 0 };
    try (CBORParser p = cborParser(input2)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Invalid UTF-8 middle byte 0x2d");
        }
    }
    // but let's also validate 3-byte variant as well
    byte[] input3 = { 0x63, (byte) 0xEF, (byte) 0x8e, 0x2d, 0, 0, 0, 0, 0, 0 };
    try (CBORParser p = cborParser(input3)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Invalid UTF-8 middle byte 0x2d");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 40 with StreamReadException

use of com.fasterxml.jackson.core.exc.StreamReadException in project jackson-dataformats-binary by FasterXML.

the class ParseInvalidUTF8String236Test method testShortString237InvalidName.

public void testShortString237InvalidName() throws Exception {
    // Object with 2-byte invalid name
    byte[] input2 = { // Object, indefinite length
    (byte) 0xBF, // 2-byte name but invalid second byte
    0x62, // 2-byte name but invalid second byte
    (byte) 0xCF, // 2-byte name but invalid second byte
    0x2e, // int value of 33
    0x21, // Object END marker
    (byte) 0xFF, // padding
    0, // padding
    0, // padding
    0, // padding
    0 };
    try (CBORParser p = cborParser(input2)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        try {
            p.nextToken();
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Invalid UTF-8 middle byte 0x2e");
        }
    }
    // but let's also validate 3-byte variant as well
    byte[] input3 = { // Object, indefinite length
    (byte) 0xBF, // 3-byte name but invalid third byte
    0x62, // 3-byte name but invalid third byte
    (byte) 0xEF, // 3-byte name but invalid third byte
    (byte) 0x8e, // 3-byte name but invalid third byte
    0x2f, // int value of 34
    0x22, // Object END marker
    (byte) 0xFF, // padding
    0, // padding
    0, // padding
    0, // padding
    0 };
    try (CBORParser p = cborParser(input3)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        try {
            p.nextToken();
            String str = p.getText();
            fail("Should have failed, did not, String = '" + str + "'");
        } catch (StreamReadException e) {
            verifyException(e, "Truncated UTF-8 character in Map key (2 bytes)");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Aggregations

StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)68 AsyncReaderWrapper (com.fasterxml.jackson.core.testsupport.AsyncReaderWrapper)23 JsonParser (com.fasterxml.jackson.core.JsonParser)15 JsonFactory (com.fasterxml.jackson.core.json.JsonFactory)11 CBORParser (com.fasterxml.jackson.dataformat.cbor.CBORParser)9 JsonToken (com.fasterxml.jackson.core.JsonToken)6 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayFeeder (com.fasterxml.jackson.core.async.ByteArrayFeeder)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URL (java.net.URL)2 Test (org.junit.Test)2 InputCoercionException (com.fasterxml.jackson.core.exc.InputCoercionException)1 WrappedIOException (com.fasterxml.jackson.core.exc.WrappedIOException)1 FilteringParserDelegate (com.fasterxml.jackson.core.filter.FilteringParserDelegate)1 ByteQuadsCanonicalizer (com.fasterxml.jackson.core.sym.ByteQuadsCanonicalizer)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 SmileGenerator (com.fasterxml.jackson.dataformat.smile.SmileGenerator)1 SmileMapper (com.fasterxml.jackson.dataformat.smile.databind.SmileMapper)1 ThrottledInputStream (com.fasterxml.jackson.dataformat.smile.testutil.ThrottledInputStream)1