Skip to content

Commit bd5479f

Browse files
author
aid270
committed
Add number size checks for IonParser getIntValue and getLongValue. Fix failing tests for FasterXML#428
1 parent de8c970 commit bd5479f

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,22 @@ public int getIntValue() throws IOException {
400400
// @since 2.17
401401
private int _getIntValue() throws IOException {
402402
try {
403-
return _reader.intValue();
403+
if (getNumberType() == NumberType.LONG) {
404+
int result = _reader.intValue();
405+
if ((long) result != _reader.longValue()) {
406+
this.reportOverflowInt();
407+
}
408+
return result;
409+
}
410+
if (getNumberType() == NumberType.BIG_INTEGER) {
411+
BigInteger bigInteger = _reader.bigIntegerValue();
412+
if (BI_MIN_INT.compareTo(bigInteger) > 0 || BI_MAX_INT.compareTo(bigInteger) < 0) {
413+
this.reportOverflowInt();
414+
}
415+
return bigInteger.intValue();
416+
} else {
417+
return _reader.intValue();
418+
}
404419
} catch (IonException
405420
// 15-Jan-2024, tatu: other OSS-Fuzz tests suggest we need this:
406421
| ArrayIndexOutOfBoundsException e) {
@@ -417,7 +432,15 @@ public long getLongValue() throws IOException {
417432
// @since 2.17
418433
private long _getLongValue() throws IOException {
419434
try {
420-
return _reader.longValue();
435+
if (this.getNumberType() == NumberType.BIG_INTEGER) {
436+
BigInteger bigInteger = _reader.bigIntegerValue();
437+
if (BI_MIN_INT.compareTo(bigInteger) > 0 || BI_MAX_INT.compareTo(bigInteger) < 0) {
438+
this.reportOverflowLong();
439+
}
440+
return bigInteger.longValue();
441+
} else {
442+
return _reader.longValue();
443+
}
421444
} catch (IonException
422445
// 14-Jan-2024, tatu: OSS-Fuzz#65731 points to AIOOBE:
423446
| ArrayIndexOutOfBoundsException e) {

0 commit comments

Comments
 (0)