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 bf5653267..21a30775d 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 @@ -413,8 +413,8 @@ private long _getLongValue() throws IOException { try { 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(); + if (BI_MIN_LONG.compareTo(bigInteger) > 0 || BI_MAX_LONG.compareTo(bigInteger) < 0) { + reportOverflowLong(); } return bigInteger.longValue(); } else { diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java index d99f10adc..8793d3c41 100644 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java @@ -3,6 +3,8 @@ import org.hamcrest.Matchers; import org.junit.Test; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; import com.fasterxml.jackson.core.exc.InputCoercionException; import static org.hamcrest.MatcherAssert.assertThat; @@ -72,4 +74,15 @@ private void _testLongCoercionFail(BigInteger input) throws Exception } } + // [dataformats-binary#569]: incorrect overflow fail for long values (from BigInteger) + @Test + public void testLongAsBigIntegerSize() throws Exception { + // Note: Values: Long.MAX_VALUE through Long.MAX_VALUE -7 are considered LONG by Ion. + BigInteger bigIntLongValue = new BigInteger(Long.MAX_VALUE + "").subtract(BigInteger.TEN); + IonParser bigIntLongParser = (IonParser) new IonFactory().createParser(bigIntLongValue.toString()); + assertEquals(JsonToken.VALUE_NUMBER_INT, bigIntLongParser.nextToken()); + assertEquals(JsonParser.NumberType.BIG_INTEGER, bigIntLongParser.getNumberType()); + assertEquals(JsonParser.NumberTypeFP.UNKNOWN, bigIntLongParser.getNumberTypeFP()); + assertEquals(bigIntLongValue.longValue(), bigIntLongParser.getLongValue()); + } } diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_469_66149_NegArraySizeTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_469_66149_NegArraySizeTest.java index 718cd098e..1f39552f9 100644 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_469_66149_NegArraySizeTest.java +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_469_66149_NegArraySizeTest.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.ion.*; -import com.fasterxml.jackson.dataformat.ion.fuzz.IonFuzzTestUtil; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.fail; diff --git a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_471_66141_AssertionErrorTest.java b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_471_66141_AssertionErrorTest.java index e6ddbfb2d..145d2b828 100644 --- a/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_471_66141_AssertionErrorTest.java +++ b/ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_471_66141_AssertionErrorTest.java @@ -6,7 +6,6 @@ import com.fasterxml.jackson.core.exc.StreamReadException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.dataformat.ion.*; -import com.fasterxml.jackson.dataformat.ion.fuzz.IonFuzzTestUtil; import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.Assert.fail; diff --git a/release-notes/VERSION-2.x b/release-notes/VERSION-2.x index 43d9e38c2..d24b136bb 100644 --- a/release-notes/VERSION-2.x +++ b/release-notes/VERSION-2.x @@ -16,6 +16,9 @@ Active maintainers: 2.18.4 (not yet released) +#569: (ion) `IonParser` fails to parse some `long` values saying + they are out of range when they are not + (reported, fix suggested by @seadbrane) - (ion) Upgrade `ion-java` to 1.11.10 (from 1.11.9) 2.18.3 (28-Feb-2025)