File tree 4 files changed +39
-18
lines changed
main/java/com/fasterxml/jackson/core/base
test/java/com/fasterxml/jackson/core/read
4 files changed +39
-18
lines changed Original file line number Diff line number Diff line change @@ -23,11 +23,18 @@ JSON library.
23
23
#484 : Implement `UTF8JsonGenerator.writeRawValue(SerializableString)` (and
24
24
`writeRaw (..)`) more efficiently
25
25
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
+
26
31
2.9 .7 (19 - Sep - 2018 )
27
32
28
33
#476 : Problem with `BufferRecycler` via async parser (or when sharing parser
29
34
across threads )
30
35
#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`)
31
38
32
39
2.9 .6 (12 - Jun - 2018 )
33
40
Original file line number Diff line number Diff line change @@ -773,7 +773,7 @@ private void _parseSlowFloat(int expType) throws IOException
773
773
}
774
774
} catch (NumberFormatException nex ) {
775
775
// 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 );
777
777
}
778
778
}
779
779
@@ -808,23 +808,14 @@ private void _parseSlowInt(int expType) throws IOException
808
808
}
809
809
} catch (NumberFormatException nex ) {
810
810
// Can this ever occur? Due to overflow, maybe?
811
- _wrapError ("Malformed numeric value '" + numStr + "' " , nex );
811
+ _wrapError ("Malformed numeric value (" + _longNumberDesc ( numStr )+ ") " , nex );
812
812
}
813
813
}
814
814
815
815
// @since 2.9.8
816
816
protected void _reportTooLongInt (int expType , String rawNum ) throws IOException
817
817
{
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 );
828
819
_reportError ("Numeric value (%s) out of range of %s" , numDesc ,
829
820
(expType == NR_LONG ) ? "long" : "int" );
830
821
}
Original file line number Diff line number Diff line change @@ -668,12 +668,36 @@ protected void reportInvalidNumber(String msg) throws JsonParseException {
668
668
669
669
protected void reportOverflowInt () throws IOException {
670
670
_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 ));
672
672
}
673
-
673
+
674
674
protected void reportOverflowLong () throws IOException {
675
675
_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 );
677
701
}
678
702
679
703
protected void _reportUnexpectedChar (int ch , String comment ) throws JsonParseException
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ public class NumberOverflowTest
23
23
24
24
private final static String BIG_POS_DOC = "[" +BIG_POS_INTEGER +"]" ;
25
25
private final static String BIG_NEG_DOC = "[ -" +BIG_POS_INTEGER +"]" ;
26
-
26
+
27
27
public void testSimpleLongOverflow () throws Exception
28
28
{
29
29
BigInteger below = BigInteger .valueOf (Long .MIN_VALUE );
@@ -54,13 +54,12 @@ public void testSimpleLongOverflow() throws Exception
54
54
verifyException (e , "out of range of long" );
55
55
}
56
56
p .close ();
57
-
58
57
}
59
58
}
60
59
61
60
// Note: only 4 cardinal types; `short`, `byte` and `char` use same code paths
62
61
// Note: due to [jackson-core#493], we'll skip DataInput-backed parser
63
-
62
+
64
63
// [jackson-core#488]
65
64
public void testMaliciousLongOverflow () throws Exception
66
65
{
You can’t perform that action at this time.
0 commit comments