Search in sources :

Example 31 with StreamReadException

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

the class Fuzz32339_7BitBinaryTest method testInvalid7BitBinary.

// Test with negative length indicator (due to overflow) -- CF-32339
public void testInvalid7BitBinary() throws Exception {
    final byte[] input0 = new byte[] { // smile signature
    0x3A, // smile signature
    0x29, // smile signature
    0x0A, // smile signature
    0x00, // binary, 7-bit encoded
    (byte) 0xE8, 0x35, 0x20, 0x20, // 5 byte VInt for 0x7fe4083f (close to Integer.MAX_VALUE)
    0x20, // 5 byte VInt for 0x7fe4083f (close to Integer.MAX_VALUE)
    (byte) 0xFF };
    // 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, "Overflow in VInt (current token VALUE_EMBEDDED_OBJECT");
            verifyException(e, "1st byte (0x35)");
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 32 with StreamReadException

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

the class Fuzz_265_32377_7BitBinaryTest method testInvalid7BitBinary.

// Test with maximum declared payload size -- CF-32377
public void testInvalid7BitBinary() throws Exception {
    final byte[] input0 = new byte[] { // smile signature
    0x3A, // smile signature
    0x29, // smile signature
    0x0A, // smile signature
    0x00, // binary, 7-bit encoded
    (byte) 0xE8, 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 };
    // 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 (7-bit)", "expected 2145650751 bytes  (from 2452172287 encoded)", "only decoded 58226");
        }
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException)

Example 33 with StreamReadException

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

the class Fuzz_291_35932_TruncUTF8NameTest method testInvalid7BitBinary.

// Test with maximum declared payload size -- CF-32377
public void testInvalid7BitBinary() throws Exception {
    final byte[] input = readResource("/data/clusterfuzz-smile-35932.smile");
    try (JsonParser p = MAPPER.createParser(input)) {
        assertToken(JsonToken.START_OBJECT, p.nextToken());
        p.nextToken();
        fail("Should not pass");
    } catch (StreamReadException e) {
        verifyException(e, "Truncated UTF-8 character in Short Unicode Name (36 bytes)");
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 34 with StreamReadException

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

the class UncaughtExceptionsTest method testUncaughtException302.

// [dataformats-binary#302]
@Test
public void testUncaughtException302() throws Exception {
    URL poc = getClass().getResource("/data/issue-302.ion");
    try {
        MAPPER.readTree(poc);
        fail("Should not pass with invalid content");
    } catch (StreamReadException e) {
        verifyException(e, "Invalid embedded TIMESTAMP");
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) URL(java.net.URL) Test(org.junit.Test)

Example 35 with StreamReadException

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

the class ParseIncompleteArray240Test method testIncompleteMarkerBasedObject.

public void testIncompleteMarkerBasedObject() throws Exception {
    final byte[] input = { (byte) 0xBF };
    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 a property or close marker");
        }
    }
}
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