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");
}
}
}
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 ");
}
}
}
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");
}
}
}
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");
}
}
}
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;
}
}
}
Aggregations