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

NPE when parsing UTF-32 byte arrays #42

Closed
jroper opened this issue Nov 16, 2012 · 7 comments
Closed

NPE when parsing UTF-32 byte arrays #42

jroper opened this issue Nov 16, 2012 · 7 comments

Comments

@jroper
Copy link
Member

jroper commented Nov 16, 2012

If you attempt to parse a UTF-32 byte array (not input stream), Jackson will throw an NPE. The bug is in here:

https://github.com/FasterXML/jackson-core/blob/master/src/main/java/com/fasterxml/jackson/core/json/ByteSourceJsonBootstrapper.java

For UTF-8 and UTF-16, a null check is done on the passed in input stream (which will be null when parsing a byte array), but for UTF-32, no null check is done, and no null check is done in UTF32Reader either.

@cowtowncoder
Copy link
Member

Apologies for the bug & congratulations for being the first UTF-32 user I have ever met! ;-D
(I assume no one has used it before, given that this is the first bug report... and for quite a fundamental bug).

@cowtowncoder
Copy link
Member

Interestingly the existing UTF-32 tested was NOT catching this issue, because it closed the stream before hitting end-of-file (which would trigger read). I was able to 'fix' this by checking for one more nextToken().
And with that, should be easy enough to fix the issue itself too.

@cowtowncoder
Copy link
Member

Fixed, now passes modified unit test. Will be in 2.1.2, 2.2.0.

@cowtowncoder
Copy link
Member

FWIW, patch fix list at: wiki.fasterxml.com/JacksonRelease212

@jroper
Copy link
Member Author

jroper commented Nov 16, 2012

Well, technically I'm not a UTF-32 user, I was just writing tests that ensured that Play framework lets Jackson detect the encoding, and included UTF-32 for completeness:

https://github.com/jroper/Play20/blob/1a467984ecd15c9f3ede8b245abb70cf4ce20184/framework/test/integrationtest-java/test/test/WsTest.java#L63

We're actually still on Jackson 1.9, but it's easy enough to work around by wrapping the byte array in a ByteArrayInputStream, so we don't need this backported.

@cowtowncoder
Copy link
Member

Fair enough, I was guessing you were probably just testing UTF-32 handling for sake of completeness. :-)
(and remembered your name from earlier submissions)

If work-around is easy, that's good; but if you do want a fix, 1.9 branch is still open. Actually, come to think of that now, how about I'll see if I can just add the fix myself. It should merge relatively cleanly.

@cowtowncoder
Copy link
Member

Fixed for 1.9.12 as well now.

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

No branches or pull requests

2 participants