-
-
Notifications
You must be signed in to change notification settings - Fork 795
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a2036e
commit f348880
Showing
4 changed files
with
71 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 51 additions & 4 deletions
55
src/test/java/com/fasterxml/jackson/core/fuzz/Fuzz32208UTF32ParseTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,74 @@ | ||
package com.fasterxml.jackson.core.fuzz; | ||
|
||
import java.io.CharConversionException; | ||
import java.io.InputStream; | ||
|
||
import com.fasterxml.jackson.core.*; | ||
import com.fasterxml.jackson.core.io.UTF32Reader; | ||
import com.fasterxml.jackson.core.testsupport.ThrottledInputStream; | ||
|
||
// Trying to repro: https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=32216 | ||
// but so far without success (fails on seemingly legit validation problem) | ||
public class Fuzz32208UTF32ParseTest extends BaseTest | ||
{ | ||
public void testFuzz32208() throws Exception | ||
private final byte[] DOC = readResource("/data/fuzz-json-utf32-32208.json"); | ||
|
||
public void testFuzz32208ViaParser() throws Exception | ||
{ | ||
final JsonFactory f = new JsonFactory(); | ||
final byte[] doc = readResource("/data/fuzz-json-utf32-32208.json"); | ||
|
||
JsonParser p = f.createParser(/*ObjectReadContext.empty(), */ doc); | ||
JsonParser p = f.createParser(/*ObjectReadContext.empty(), */ DOC); | ||
try { | ||
assertToken(JsonToken.VALUE_STRING, p.nextToken()); | ||
String text = p.getText(); | ||
fail("Should not have passed; got text with length of: "+text.length()); | ||
} catch (CharConversionException e) { | ||
//e.printStackTrace(); | ||
verifyException(e, "Invalid UTF-32 character "); | ||
} | ||
p.close(); | ||
} | ||
|
||
// How about through UTF32Reader itself? | ||
public void testFuzz32208Direct() throws Exception | ||
{ | ||
_testFuzz32208Direct(1); | ||
_testFuzz32208Direct(2); | ||
_testFuzz32208Direct(3); | ||
_testFuzz32208Direct(7); | ||
_testFuzz32208Direct(13); | ||
_testFuzz32208Direct(67); | ||
_testFuzz32208Direct(111); | ||
_testFuzz32208Direct(337); | ||
_testFuzz32208Direct(991); | ||
} | ||
|
||
private void _testFuzz32208Direct(int readSize) throws Exception | ||
{ | ||
InputStream in = new ThrottledInputStream(DOC, readSize); | ||
// apparently input is NOT big-endian so: | ||
UTF32Reader r = new UTF32Reader(null, in, new byte[500], 0, 0, false); | ||
|
||
int count = 0; | ||
int ch; | ||
|
||
try { | ||
final char[] chunkBuffer = new char[19]; | ||
|
||
while (true) { | ||
ch = r.read(chunkBuffer); | ||
if (ch == -1) { | ||
break; | ||
} | ||
if (ch == 0) { | ||
fail("Received 0 chars; broken reader"); | ||
} | ||
count += ch; | ||
} | ||
fail("Should have failed, got all "+count+" characters, last 0x"+Integer.toHexString(ch)); | ||
} catch (CharConversionException e) { | ||
verifyException(e, "Invalid UTF-32 character "); | ||
} | ||
|
||
r.close(); | ||
} | ||
} |