Skip to content

Commit d91f7a3

Browse files
authored
Additional fix for issue 449 (#453)
1 parent 170cbaa commit d91f7a3

File tree

4 files changed

+56
-15
lines changed

4 files changed

+56
-15
lines changed

avro/src/main/java/com/fasterxml/jackson/dataformat/avro/deser/JacksonAvroParserImpl.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,13 @@ private final void _finishLongText(int len) throws IOException
700700
break;
701701
case 3: // 4-byte UTF
702702
c = _decodeUTF8_4(c);
703-
// Let's add first part right away:
704-
outBuf[outPtr++] = (char) (0xD800 | (c >> 10));
705703
if (outPtr >= outBuf.length) {
706704
outBuf = _textBuffer.finishCurrentSegment();
707705
outPtr = 0;
708706
outEnd = outBuf.length;
709707
}
708+
// Let's add first part right away:
709+
outBuf[outPtr++] = (char) (0xD800 | (c >> 10));
710710
c = 0xDC00 | (c & 0x3FF);
711711
// And let the other char output down below
712712
break;

avro/src/test/java/com/fasterxml/jackson/dataformat/avro/fuzz/AvroFuzz449_65618_IOOBETest.java renamed to avro/src/test/java/com/fasterxml/jackson/dataformat/avro/fuzz/AvroFuzz449_65618_65649_IOOBETest.java

+23-13
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,44 @@
1212
import com.fasterxml.jackson.dataformat.avro.AvroTestBase;
1313

1414
// [dataformats-binary#449]
15-
public class AvroFuzz449_65618_IOOBETest extends AvroTestBase
15+
public class AvroFuzz449_65618_65649_IOOBETest extends AvroTestBase
1616
{
1717
@JsonPropertyOrder({ "name", "value" })
1818
static class RootType {
1919
public String name;
2020
public int value;
2121
}
2222

23-
@Test
24-
public void testFuzz65618IOOBE() throws Exception {
25-
final AvroFactory factory = AvroFactory.builderWithNativeDecoder().build();
26-
final AvroMapper mapper = new AvroMapper(factory);
27-
28-
final byte[] doc = {
29-
(byte) 2, (byte) 22, (byte) 36, (byte) 2, (byte) 0,
30-
(byte) 0, (byte) 8, (byte) 3, (byte) 3, (byte) 3,
31-
(byte) 122, (byte) 3, (byte) -24
32-
};
23+
final private AvroFactory factory = AvroFactory.builderWithNativeDecoder().build();
24+
final private AvroMapper mapper = new AvroMapper(factory);
3325

26+
private void testFuzzIOOBE(byte[] input, String msg) throws Exception {
3427
final AvroSchema schema = mapper.schemaFor(RootType.class);
35-
try (AvroParser p = (AvroParser) mapper.createParser(doc)) {
28+
try (AvroParser p = (AvroParser) mapper.createParser(input)) {
3629
p.setSchema(schema);
3730
assertToken(JsonToken.START_OBJECT, p.nextToken());
3831
assertToken(JsonToken.FIELD_NAME, p.nextToken());
3932
p.nextToken();
33+
p.nextToken();
4034
fail("Should not pass (invalid content)");
4135
} catch (StreamReadException e) {
42-
verifyException(e, "Malformed 2-byte UTF-8 character at the end of");
36+
verifyException(e, msg);
4337
}
4438
}
39+
40+
@Test
41+
public void testFuzz65618_IOOBE() throws Exception {
42+
final byte[] doc = {
43+
(byte) 2, (byte) 22, (byte) 36, (byte) 2, (byte) 0,
44+
(byte) 0, (byte) 8, (byte) 3, (byte) 3, (byte) 3,
45+
(byte) 122, (byte) 3, (byte) -24
46+
};
47+
testFuzzIOOBE(doc, "Malformed 2-byte UTF-8 character at the end of");
48+
}
49+
50+
@Test
51+
public void testFuzz65649_IOOBE() throws Exception {
52+
final byte[] doc = AvroFuzzTestUtil.readResource("/data/fuzz-65649.avro");
53+
testFuzzIOOBE(doc, "Invalid UTF-8 start byte 0x80");
54+
}
4555
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.fasterxml.jackson.dataformat.avro.fuzz;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.IOException;
5+
import java.io.InputStream;
6+
7+
public class AvroFuzzTestUtil
8+
{
9+
public static byte[] readResource(String ref)
10+
{
11+
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
12+
final byte[] buf = new byte[4000];
13+
14+
InputStream in = AvroFuzzTestUtil.class.getResourceAsStream(ref);
15+
if (in != null) {
16+
try {
17+
int len;
18+
while ((len = in.read(buf)) > 0) {
19+
bytes.write(buf, 0, len);
20+
}
21+
in.close();
22+
} catch (IOException e) {
23+
throw new RuntimeException("Failed to read resource '"+ref+"': "+e);
24+
}
25+
}
26+
if (bytes.size() == 0) {
27+
throw new IllegalArgumentException("Failed to read resource '"+ref+"': empty resource?");
28+
}
29+
return bytes.toByteArray();
30+
}
31+
}
307 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)