Search in sources :

Example 26 with StreamReadException

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

the class Fuzz289_35822_TruncatedNameTest method testInvalidSplitUtf8Unit.

// As per https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=35822
// ArrayIndexOutOfBoundsException when 2 out of 3 bytes available before
// end-of-input
public void testInvalidSplitUtf8Unit() throws Exception {
    final byte[] input = new byte[] { // Object, 6 entries
    (byte) 0xA6, // String (key), length 2 (non-canonical)
    0x78, // String (key), length 2 (non-canonical)
    0x02, // broken UTF-8 codepoint
    (byte) 0xE6, // broken UTF-8 codepoint
    (byte) 0x8B };
    try (JsonParser p = MAPPER.createParser(input)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        try {
            assertToken(JsonToken.PROPERTY_NAME, p.nextToken());
            fail("Should not pass");
        } catch (StreamReadException e) {
            verifyException(e, "Truncated UTF-8");
            verifyException(e, "byte 0xE6 at offset #0 indicated 2 more bytes needed");
        }
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 27 with StreamReadException

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

the class ParseIncompleteArray240Test method testIncompleteMarkerBasedArray.

public void testIncompleteMarkerBasedArray() throws Exception {
    final byte[] input = { (byte) 0x9F };
    try (CBORParser p = cborParser(F, input)) {
        assertToken(JsonToken.START_ARRAY, p.nextToken());
        try {
            p.nextToken();
            fail("Should NOT pass");
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input in Array value: expected an element or ");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 28 with StreamReadException

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

the class ParseIncompleteArray240Test method testIncompleteFixedSizeArray.

// [dataformats-binary#240]
public void testIncompleteFixedSizeArray() throws Exception {
    final byte[] input = { (byte) 0x84 };
    try (CBORParser p = cborParser(F, input)) {
        assertToken(JsonToken.START_ARRAY, p.nextToken());
        try {
            p.nextToken();
            fail("Should NOT pass");
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input in Array value: expected 4 more");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 29 with StreamReadException

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

the class ParseInvalidUTF8String236Test method testShortString236Original.

// [dataformats-binary#236]: Original version; broken UTF-8 all around.
// but gets hit by end-of-input only (since content not validated)
public void testShortString236Original() throws Exception {
    final byte[] input = { 0x66, (byte) 0xef, 0x7d, 0x7d, 0xa, 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, "Invalid UTF-8 middle byte 0x7d");
        }
    }
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 30 with StreamReadException

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

the class Fuzz32180RawBinaryTest method testInvalidRawBinary.

public void testInvalidRawBinary() throws Exception {
    final byte[] input0 = new byte[] { // smile signature
    0x3A, // smile signature
    0x29, // smile signature
    0x0A, // smile signature
    0x00, // raw binary
    (byte) 0xFD, 0x0F, 0x7E, 0x20, // 5 byte VInt for 0x7fe4083f (close to Integer.MAX_VALUE)
    0x20, // 5 byte VInt for 0x7fe4083f (close to Integer.MAX_VALUE)
    (byte) 0xFF, // and one byte of binary payload
    0x00 };
    // Let's expand slightly to avoid too early detection, ensure that we are
    // not only checking completely missing payload or such
    final byte[] input = Arrays.copyOf(input0, 65 * 1024);
    try (ByteArrayInputStream bytes = new ByteArrayInputStream(input)) {
        try {
            /*JsonNode root =*/
            MAPPER.readTree(bytes);
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input for Binary value (raw): expected 2145650751 bytes, only found 66550");
        } catch (OutOfMemoryError e) {
            // Just to make it easier to see on fail (not ideal but better than nothing)
            e.printStackTrace();
            throw e;
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) 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