Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayIndexOutOfBoundsException from UTF32Reader.read on invalid input #418

Closed
pfitzsimons-r7 opened this issue Oct 17, 2017 · 3 comments · Fixed by #419
Closed

ArrayIndexOutOfBoundsException from UTF32Reader.read on invalid input #418

pfitzsimons-r7 opened this issue Oct 17, 2017 · 3 comments · Fixed by #419
Milestone

Comments

@pfitzsimons-r7
Copy link

I was doing some fuzz testing and came across an ArrayIndexOutOfBoundsException. It seems like it is related to /issues/382 in that it has introduced a bug which if the byte[] is a %3 it will still produce an ArrayIndexOutOfBoundsException.

Simple test case as follows:

public void testInvalidInput() throws IOException {
        byte[] data = new byte[7];
        JsonParser parser = FACTORY.createParser(ObjectReadContext.empty(), data);
        parser.nextToken();
        parser.close();
    }

Stack trace:

java.lang.ArrayIndexOutOfBoundsException: 7

	at com.fasterxml.jackson.core.io.UTF32Reader.read(UTF32Reader.java:145)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._loadMore(ReaderBasedJsonParser.java:229)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:2316)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:632)
	at com.fasterxml.jackson.core.read.UTF32ParseTest.testInvalidInput(UTF32ParseTest.java:61)

Just for clarity the following test case produces the correct JsonParseExecption

public void testInvalidInput() throws IOException {
        byte[] data = new byte[8];
        JsonParser parser = FACTORY.createParser(ObjectReadContext.empty(), data);
        parser.nextToken();
        parser.close();
    }

Stack trace:

com.fasterxml.jackson.core.JsonParseException: Illegal character ((CTRL-CHAR, code 0)): only regular white space (\r, \n, \t) is allowed between tokens
 at [Source: (byte[])"        "; line: 1, column: 2]

	at com.fasterxml.jackson.core.JsonParser._constructError(JsonParser.java:1666)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._reportError(ParserMinimalBase.java:674)
	at com.fasterxml.jackson.core.base.ParserMinimalBase._throwInvalidSpace(ParserMinimalBase.java:625)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser._skipWSOrEnd(ReaderBasedJsonParser.java:2335)
	at com.fasterxml.jackson.core.json.ReaderBasedJsonParser.nextToken(ReaderBasedJsonParser.java:632)
	at com.fasterxml.jackson.core.read.UTF32ParseTest.testInvalidInput(UTF32ParseTest.java:61)
@cowtowncoder
Copy link
Member

Thank you for reporting this. While UTF-32 isn't widely (or at all?) used, implementation if one exists should work correctly.

@pfitzsimons-r7
Copy link
Author

See attached pr /pull/419 @cowtowncoder

@cowtowncoder
Copy link
Member

Excellent! I'll add one note on PR which is needed and I can merge the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants