diff --git a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java index cd505ff56..ecde53318 100644 --- a/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java +++ b/ion/src/main/java/com/fasterxml/jackson/dataformat/ion/IonParser.java @@ -381,7 +381,23 @@ public int getIntValue() throws IOException { // @since 2.17 private int _getIntValue() throws IOException { try { - return _reader.intValue(); + NumberType numberType = getNumberType(); + if (numberType == NumberType.LONG) { + int result = _reader.intValue(); + if ((long) result != _reader.longValue()) { + this.reportOverflowInt(); + } + return result; + } + if (numberType == 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 e) { return _reportCorruptNumber(e); } @@ -396,7 +412,15 @@ public long getLongValue() throws IOException { // @since 2.17 private long _getLongValue() throws IOException { try { - return _reader.longValue(); + 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 e) { return _reportCorruptNumber(e); } diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/failing/IonNumberOverflow428Test.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java similarity index 94% rename from ion/src/test/java/com/fasterxml/jackson/dataformat/ion/failing/IonNumberOverflow428Test.java rename to ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java index 128353045..d99f10adc 100644 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/failing/IonNumberOverflow428Test.java +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java @@ -1,10 +1,9 @@ -package com.fasterxml.jackson.dataformat.ion.failing; +package com.fasterxml.jackson.dataformat.ion; import org.hamcrest.Matchers; import org.junit.Test; import com.fasterxml.jackson.core.exc.InputCoercionException; -import com.fasterxml.jackson.dataformat.ion.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.assertEquals; @@ -13,7 +12,7 @@ import java.math.BigInteger; // for [dataformats-ion#428] -public class IonNumberOverflow428Test +public class IonNumberOverflowTest { private final IonObjectMapper MAPPER = IonObjectMapper .builderForBinaryWriters() diff --git a/release-notes/CREDITS-2.x b/release-notes/CREDITS-2.x index 37beee482..38da6d77b 100644 --- a/release-notes/CREDITS-2.x +++ b/release-notes/CREDITS-2.x @@ -314,3 +314,8 @@ Arthur Chan (@arthurscchan) * Contributed #464: (cbor) Unexpected `ArrayIndexOutOfBoundsException` in `CBORParser` for corrupt String value (2.17.0) + +Thomas de Lange (@thomasdelange5) + * Contributed fix for #428: (ion) `IonParser.getIntValue()` fails or does not handle + value overflow checks + (2.17.0) diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 581a2d3e7..2583b03a1 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -31,7 +31,9 @@ Active maintainers: #424: (ion) `IonReader` throws `NullPointerException` for unchecked invalid data (fix contributed by Arthur C) #426: (smile) `SmileParser` throws unexpected IOOBE for corrupt content - (fix contributed by Arthur C)-( + (fix contributed by Arthur C) +#428: (ion) `IonParser.getIntValue()` fails or does not handle value overflow checks + (fix contributed by Thomas d-L) #432: (ion) More methods from `IonReader` could throw an unexpected `AssertionError` (fix contributed by Arthur C) #434: (ion) Unexpected `NullPointerException` thrown from `IonParser::getNumberType()`