Search in sources :

Example 41 with StreamReadException

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

the class BrokenLongBinary186Test method _testCorruptLong.

private void _testCorruptLong(int allegedLength, int actualIncluded) {
    JsonParser p = MAPPER.createParser(_createBrokenDoc(allegedLength, actualIncluded));
    assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken());
    try {
        p.getBinaryValue();
        fail("Should fail");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected end-of-input for Binary value");
        verifyException(e, "expected " + allegedLength + " bytes, only found " + actualIncluded);
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 42 with StreamReadException

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

the class BrokenLongBinary186Test method testQuiteLongStreaming.

/*
    /**********************************************************************
    /* And then "streaming" access
    /**********************************************************************
     */
// [dataformats-binary#186]
public void testQuiteLongStreaming() throws Exception {
    // Can try bit shorter here, like 500 megs
    final int allegedLength = 500_000_000;
    JsonParser p = MAPPER.createParser(_createBrokenDoc(allegedLength, 72000));
    assertEquals(JsonToken.VALUE_EMBEDDED_OBJECT, p.nextToken());
    try {
        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        p.readBinaryValue(bytes);
        fail("Should fail");
    } catch (StreamReadException e) {
        verifyException(e, "Unexpected end-of-input for Binary value");
        verifyException(e, "expected " + allegedLength + " bytes, only found 72000");
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 43 with StreamReadException

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

the class Fuzz273_32912_ChunkedTextTest method testChunkedWithUTF8_4Bytes_v2.

// [dataformats-binary#273]
// (see https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32912)
public void testChunkedWithUTF8_4Bytes_v2() throws Exception {
    final byte[] input = new byte[] { // text, chunked (length marker 0x1F)
    (byte) 0x7F, // text segment of 1 bytes.
    0x61, // First byte of 4-byte UTF-8 character
    (byte) 0xF3, // (invalid) second byte of 4-byte UTF-8 character
    0x61 };
    try (JsonParser p = MAPPER.createParser(input)) {
        assertToken(JsonToken.VALUE_STRING, p.nextToken());
        try {
            p.getText();
            fail("Should not pass, invalid content");
        } catch (StreamReadException e) {
            verifyException(e, "Unexpected end-of-input in VALUE_STRING");
        }
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 44 with StreamReadException

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

the class SimpleValuesTest method testInvalidByteLengthMinimalValues.

public void testInvalidByteLengthMinimalValues() {
    // Values 0..31 are invalid for variant that takes 2 bytes...
    for (int v = 0; v <= 31; ++v) {
        byte[] doc = { (byte) (CBORConstants.PREFIX_TYPE_MISC + 24), (byte) v };
        try (JsonParser p = cborParser(doc)) {
            try {
                p.nextToken();
                fail("Should not pass");
            } catch (StreamReadException e) {
                verifyException(e, "Invalid second byte for simple value:");
                verifyException(e, "0x" + Integer.toHexString(v));
            }
        }
    }
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

Example 45 with StreamReadException

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

the class POJOSimpleReadTest method testMissingSchema.

public void testMissingSchema() throws Exception {
    Employee empl = _simpleEmployee();
    byte[] avro = toAvro(empl);
    JsonParser p = MAPPER.createParser(avro);
    try {
        p.nextToken();
        fail("Should not pass");
    } catch (StreamReadException e) {
        verifyException(e, "No AvroSchema set");
    }
    p.close();
}
Also used : StreamReadException(com.fasterxml.jackson.core.exc.StreamReadException) JsonParser(com.fasterxml.jackson.core.JsonParser)

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