-
-
Notifications
You must be signed in to change notification settings - Fork 141
Handle value overflow checks for IonParser.getIntValue() - #428 #481
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
Changes from 2 commits
bd5479f
4d9339f
0426455
17ed036
c8765b2
09088d2
8b1c93d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,8 +390,25 @@ public int getIntValue() throws IOException { | |
// @since 2.17 | ||
private int _getIntValue() throws IOException { | ||
try { | ||
return _reader.intValue(); | ||
} catch (IonException e) { | ||
if (getNumberType() == NumberType.LONG) { | ||
int result = _reader.intValue(); | ||
if ((long) result != _reader.longValue()) { | ||
this.reportOverflowInt(); | ||
} | ||
return result; | ||
} | ||
if (getNumberType() == NumberType.BIG_INTEGER) { | ||
BigInteger bigInteger = _reader.bigIntegerValue(); | ||
if (BI_MIN_INT.compareTo(bigInteger) > 0 || BI_MAX_INT.compareTo(bigInteger) < 0) { | ||
this.reportOverflowInt(); | ||
} | ||
return bigInteger.intValue(); | ||
} else { | ||
return _reader.intValue(); | ||
} | ||
} catch (IonException | ||
// 15-Jan-2024, tatu: other OSS-Fuzz tests suggest we need this: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's not add this back (I think @tgregg is working on handling these edge cases) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Correct. If fuzzing identifies any new leaked exceptions I'd like to fix those in ion-java; in the meantime we can cover them in |
||
| ArrayIndexOutOfBoundsException e) { | ||
return _reportCorruptNumber(e); | ||
} | ||
} | ||
|
@@ -405,8 +422,18 @@ public long getLongValue() throws IOException { | |
// @since 2.17 | ||
private long _getLongValue() throws IOException { | ||
try { | ||
return _reader.longValue(); | ||
} catch (IonException e) { | ||
if (this.getNumberType() == NumberType.BIG_INTEGER) { | ||
BigInteger bigInteger = _reader.bigIntegerValue(); | ||
if (BI_MIN_INT.compareTo(bigInteger) > 0 || BI_MAX_INT.compareTo(bigInteger) < 0) { | ||
this.reportOverflowLong(); | ||
} | ||
return bigInteger.longValue(); | ||
} else { | ||
return _reader.longValue(); | ||
} | ||
} catch (IonException | ||
// 14-Jan-2024, tatu: OSS-Fuzz#65731 points to AIOOBE: | ||
| ArrayIndexOutOfBoundsException e) { | ||
return _reportCorruptNumber(e); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor: for performance reasons, I recommend storing this value and using it in both branches. ion-java has to do some bounds checking on the values, and we should avoid doing that twice when possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok will do. Thanks @tgregg
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was about to suggest same, +1