Skip to content

Commit e306fa6

Browse files
authored
add stream test to csv test case 497 (#541)
1 parent eaed271 commit e306fa6

File tree

2 files changed

+36
-7
lines changed

2 files changed

+36
-7
lines changed

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/deser/FuzzCSVReadTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.dataformat.csv.deser;
22

3+
import java.io.ByteArrayInputStream;
34
import java.io.IOException;
45

56
import org.junit.jupiter.api.Test;
@@ -14,12 +15,12 @@
1415
public class FuzzCSVReadTest extends StreamingCSVReadTest
1516
{
1617
private final CsvMapper CSV_MAPPER = mapperForCsv();
18+
private final byte[] INPUT = new byte[] { 0x20, (byte) 0xCD };
1719

1820
// https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=50036
1921
@Test
2022
public void testUTF8Decoding50036() throws Exception
2123
{
22-
byte[] INPUT = new byte[] { 0x20, (byte) 0xCD };
2324
try {
2425
CSV_MAPPER.readTree(INPUT);
2526
fail("Should not pass");
@@ -28,4 +29,15 @@ public void testUTF8Decoding50036() throws Exception
2829
verifyException(e, "of a UTF-8 character");
2930
}
3031
}
32+
33+
@Test
34+
public void testUTF8Decoding50036Stream() throws Exception
35+
{
36+
try {
37+
CSV_MAPPER.readTree(new ByteArrayInputStream(INPUT));
38+
fail("Should not pass");
39+
} catch (IOException e) {
40+
verifyException(e, "Unexpected EOF in the middle of a multi-byte UTF-8 character");
41+
}
42+
}
3143
}

csv/src/test/java/com/fasterxml/jackson/dataformat/csv/tofix/UnicodeCSVRead497Test.java

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.fasterxml.jackson.dataformat.csv.tofix;
22

3+
import java.io.ByteArrayInputStream;
34
import java.nio.charset.StandardCharsets;
45

56
import org.junit.jupiter.api.Test;
@@ -21,17 +22,33 @@ public class UnicodeCSVRead497Test extends ModuleTestBase
2122
@Test
2223
public void testUnicodeAtEnd() throws Exception
2324
{
24-
StringBuilder sb = new StringBuilder(4001);
25-
for (int i = 0; i < 4000; ++i) {
26-
sb.append('a');
27-
}
28-
sb.append('\u5496');
29-
String doc = sb.toString();
25+
String doc = buildTestString();
3026
JsonNode o = MAPPER.reader() //.with(schema)
3127
.readTree(doc.getBytes(StandardCharsets.UTF_8));
3228
assertNotNull(o);
3329
assertTrue(o.isArray());
3430
assertEquals(1, o.size());
3531
assertEquals(o.get(0).textValue(), doc);
3632
}
33+
34+
@Test
35+
public void testUnicodeAtEndStream() throws Exception
36+
{
37+
String doc = buildTestString();
38+
JsonNode o = MAPPER.reader() //.with(schema)
39+
.readTree(new ByteArrayInputStream(doc.getBytes(StandardCharsets.UTF_8)));
40+
assertNotNull(o);
41+
assertTrue(o.isArray());
42+
assertEquals(1, o.size());
43+
assertEquals(o.get(0).textValue(), doc);
44+
}
45+
46+
private static String buildTestString() {
47+
StringBuilder sb = new StringBuilder(4001);
48+
for (int i = 0; i < 4000; ++i) {
49+
sb.append('a');
50+
}
51+
sb.append('\u5496');
52+
return sb.toString();
53+
}
3754
}

0 commit comments

Comments
 (0)