Skip to content

Commit a24507e

Browse files
committed
Merge branch '2.10'
2 parents abb40fc + 17a3394 commit a24507e

File tree

4 files changed

+39
-18
lines changed

4 files changed

+39
-18
lines changed

release-notes/VERSION-2.x

+7
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,18 @@ JSON library.
2323
#484: Implement `UTF8JsonGenerator.writeRawValue(SerializableString)` (and
2424
`writeRaw(..)`) more efficiently
2525

26+
2.9.8 (not yet released)
27+
28+
#488: Fail earlier on coercions from "too big" `BigInteger` into
29+
fixed-size types (`int`, `long`, `short`)
30+
2631
2.9.7 (19-Sep-2018)
2732

2833
#476: Problem with `BufferRecycler` via async parser (or when sharing parser
2934
across threads)
3035
#477: Exception while decoding Base64 value with escaped `=` character
36+
#488: Fail earlier on coercions from "too big" `BigInteger` into
37+
fixed-size types (`int`, `long`, `short`)
3138

3239
2.9.6 (12-Jun-2018)
3340

src/main/java/com/fasterxml/jackson/core/base/ParserBase.java

+3-12
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,7 @@ private void _parseSlowFloat(int expType) throws IOException
773773
}
774774
} catch (NumberFormatException nex) {
775775
// Can this ever occur? Due to overflow, maybe?
776-
_wrapError("Malformed numeric value '"+_textBuffer.contentsAsString()+"'", nex);
776+
_wrapError("Malformed numeric value ("+_longNumberDesc(_textBuffer.contentsAsString())+")", nex);
777777
}
778778
}
779779

@@ -808,23 +808,14 @@ private void _parseSlowInt(int expType) throws IOException
808808
}
809809
} catch (NumberFormatException nex) {
810810
// Can this ever occur? Due to overflow, maybe?
811-
_wrapError("Malformed numeric value '"+numStr+"'", nex);
811+
_wrapError("Malformed numeric value ("+_longNumberDesc(numStr)+")", nex);
812812
}
813813
}
814814

815815
// @since 2.9.8
816816
protected void _reportTooLongInt(int expType, String rawNum) throws IOException
817817
{
818-
int rawLen = rawNum.length();
819-
final String numDesc;
820-
if (rawLen < 1000) {
821-
numDesc = rawNum;
822-
} else {
823-
if (rawNum.startsWith("-")) {
824-
rawLen -= 1;
825-
}
826-
numDesc = String.format("[Integer with %d digits]", rawLen);
827-
}
818+
final String numDesc = _longIntegerDesc(rawNum);
828819
_reportError("Numeric value (%s) out of range of %s", numDesc,
829820
(expType == NR_LONG) ? "long" : "int");
830821
}

src/main/java/com/fasterxml/jackson/core/base/ParserMinimalBase.java

+27-3
Original file line numberDiff line numberDiff line change
@@ -668,12 +668,36 @@ protected void reportInvalidNumber(String msg) throws JsonParseException {
668668

669669
protected void reportOverflowInt() throws IOException {
670670
_reportError(String.format("Numeric value (%s) out of range of int (%d - %s)",
671-
getText(), Integer.MIN_VALUE, Integer.MAX_VALUE));
671+
_longIntegerDesc(getText()), Integer.MIN_VALUE, Integer.MAX_VALUE));
672672
}
673-
673+
674674
protected void reportOverflowLong() throws IOException {
675675
_reportError(String.format("Numeric value (%s) out of range of long (%d - %s)",
676-
getText(), Long.MIN_VALUE, Long.MAX_VALUE));
676+
_longIntegerDesc(getText()), Long.MIN_VALUE, Long.MAX_VALUE));
677+
}
678+
679+
// @since 2.9.8
680+
protected String _longIntegerDesc(String rawNum) {
681+
int rawLen = rawNum.length();
682+
if (rawLen < 1000) {
683+
return rawNum;
684+
}
685+
if (rawNum.startsWith("-")) {
686+
rawLen -= 1;
687+
}
688+
return String.format("[Integer with %d digits]", rawLen);
689+
}
690+
691+
// @since 2.9.8
692+
protected String _longNumberDesc(String rawNum) {
693+
int rawLen = rawNum.length();
694+
if (rawLen < 1000) {
695+
return rawNum;
696+
}
697+
if (rawNum.startsWith("-")) {
698+
rawLen -= 1;
699+
}
700+
return String.format("[number with %d characters]", rawLen);
677701
}
678702

679703
protected void _reportUnexpectedChar(int ch, String comment) throws JsonParseException

src/test/java/com/fasterxml/jackson/core/read/NumberOverflowTest.java

+2-3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class NumberOverflowTest
2323

2424
private final static String BIG_POS_DOC = "["+BIG_POS_INTEGER+"]";
2525
private final static String BIG_NEG_DOC = "[ -"+BIG_POS_INTEGER+"]";
26-
26+
2727
public void testSimpleLongOverflow() throws Exception
2828
{
2929
BigInteger below = BigInteger.valueOf(Long.MIN_VALUE);
@@ -54,13 +54,12 @@ public void testSimpleLongOverflow() throws Exception
5454
verifyException(e, "out of range of long");
5555
}
5656
p.close();
57-
5857
}
5958
}
6059

6160
// Note: only 4 cardinal types; `short`, `byte` and `char` use same code paths
6261
// Note: due to [jackson-core#493], we'll skip DataInput-backed parser
63-
62+
6463
// [jackson-core#488]
6564
public void testMaliciousLongOverflow() throws Exception
6665
{

0 commit comments

Comments
 (0)