Skip to content

Commit 78bbc61

Browse files
authored
Fix #569: incorrect overflow reporting (#570)
1 parent aefad8f commit 78bbc61

File tree

5 files changed

+18
-4
lines changed

5 files changed

+18
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,8 +413,8 @@ private long _getLongValue() throws IOException {
413413
try {
414414
if (this.getNumberType() == NumberType.BIG_INTEGER) {
415415
BigInteger bigInteger = _reader.bigIntegerValue();
416-
if (BI_MIN_INT.compareTo(bigInteger) > 0 || BI_MAX_INT.compareTo(bigInteger) < 0) {
417-
this.reportOverflowLong();
416+
if (BI_MIN_LONG.compareTo(bigInteger) > 0 || BI_MAX_LONG.compareTo(bigInteger) < 0) {
417+
reportOverflowLong();
418418
}
419419
return bigInteger.longValue();
420420
} else {

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/IonNumberOverflowTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import org.hamcrest.Matchers;
44
import org.junit.Test;
55

6+
import com.fasterxml.jackson.core.JsonParser;
7+
import com.fasterxml.jackson.core.JsonToken;
68
import com.fasterxml.jackson.core.exc.InputCoercionException;
79

810
import static org.hamcrest.MatcherAssert.assertThat;
@@ -72,4 +74,15 @@ private void _testLongCoercionFail(BigInteger input) throws Exception
7274
}
7375
}
7476

77+
// [dataformats-binary#569]: incorrect overflow fail for long values (from BigInteger)
78+
@Test
79+
public void testLongAsBigIntegerSize() throws Exception {
80+
// Note: Values: Long.MAX_VALUE through Long.MAX_VALUE -7 are considered LONG by Ion.
81+
BigInteger bigIntLongValue = new BigInteger(Long.MAX_VALUE + "").subtract(BigInteger.TEN);
82+
IonParser bigIntLongParser = (IonParser) new IonFactory().createParser(bigIntLongValue.toString());
83+
assertEquals(JsonToken.VALUE_NUMBER_INT, bigIntLongParser.nextToken());
84+
assertEquals(JsonParser.NumberType.BIG_INTEGER, bigIntLongParser.getNumberType());
85+
assertEquals(JsonParser.NumberTypeFP.UNKNOWN, bigIntLongParser.getNumberTypeFP());
86+
assertEquals(bigIntLongValue.longValue(), bigIntLongParser.getLongValue());
87+
}
7588
}

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_469_66149_NegArraySizeTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.fasterxml.jackson.core.exc.StreamReadException;
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.fasterxml.jackson.dataformat.ion.*;
9-
import com.fasterxml.jackson.dataformat.ion.fuzz.IonFuzzTestUtil;
109

1110
import static org.hamcrest.MatcherAssert.assertThat;
1211
import static org.junit.Assert.fail;

ion/src/test/java/com/fasterxml/jackson/dataformat/ion/fuzz/IonFuzz_471_66141_AssertionErrorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import com.fasterxml.jackson.core.exc.StreamReadException;
77
import com.fasterxml.jackson.databind.ObjectMapper;
88
import com.fasterxml.jackson.dataformat.ion.*;
9-
import com.fasterxml.jackson.dataformat.ion.fuzz.IonFuzzTestUtil;
109

1110
import static org.hamcrest.MatcherAssert.assertThat;
1211
import static org.junit.Assert.fail;

release-notes/VERSION-2.x

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ Active maintainers:
1616

1717
2.18.4 (not yet released)
1818

19+
#569: (ion) `IonParser` fails to parse some `long` values saying
20+
they are out of range when they are not
21+
(reported, fix suggested by @seadbrane)
1922
- (ion) Upgrade `ion-java` to 1.11.10 (from 1.11.9)
2023

2124
2.18.3 (28-Feb-2025)

0 commit comments

Comments
 (0)