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

Integer bounds verification when calling TokenBuffer.getIntValue() #1729

Closed
newkek opened this issue Aug 11, 2017 · 1 comment
Closed

Integer bounds verification when calling TokenBuffer.getIntValue() #1729

newkek opened this issue Aug 11, 2017 · 1 comment
Milestone

Comments

@newkek
Copy link

newkek commented Aug 11, 2017

Hello,

Using the TokenBuffer API I have noticed some unexpected behaviour wrt to 32 bit integers limits when deserializing a constructed TokenBuffer. It seems like when calling getIntValue() where the number value is bigger than the Java integer (32bit) limit might produce a wrong result instead of throwing an exception saying the number is too big. When not using a TokenBuffer parser, but when an implementation of ParserBase is used, I get some expected exceptions saying Numeric value ... out of range of int.

Here's a TokenBuffer example:

TokenBuffer tb = new TokenBuffer(new ObjectMapper(), false);
tb.writeNumber("-4294967295");

JsonParser jp = tb.asParser();
jp.nextToken();

System.out.println("jp.getIntValue() = " + jp.getIntValue());
// returned value is 1

(using a recent 2.9.1-SNAPSHOT build)

However as you can see here, ParserBase.getIntValue() tries to convert the int, which if not valid fails, and throws the expected exception of int overflow.

Thanks.

@cowtowncoder
Copy link
Member

That does sound like a flaw: I think behavior should be identical. One can not rely on generator side of TokenBuffer to guard against it as it is possible to add a long or BigInteger and try to read as int.

Thank you for reporting this.

@cowtowncoder cowtowncoder changed the title Integer bounds verification when calling JsonParser.getIntValue() Integer bounds verification when calling TokenBuffer.getIntValue() Jan 3, 2018
@cowtowncoder cowtowncoder added this to the 2.9.4 milestone Jan 3, 2018
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