Skip to content

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +12,7 @@
import java.math.BigInteger;

// for [dataformats-ion#428]
public class IonNumberOverflow428Test
public class IonNumberOverflowTest
{
private final IonObjectMapper MAPPER = IonObjectMapper
.builderForBinaryWriters()
Expand Down
5 changes: 5 additions & 0 deletions release-notes/CREDITS-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion release-notes/VERSION-2.x
Original file line number Diff line number Diff line change
Expand Up @@ -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()`
Expand Down