File tree Expand file tree Collapse file tree 4 files changed +36
-1
lines changed
main/java/com/fasterxml/jackson/core/io
test/java/com/fasterxml/jackson/core/io Expand file tree Collapse file tree 4 files changed +36
-1
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,10 @@ Vlad Tatavu (vladt@github)
287287 for "content reference"
288288 (2.13 .2 )
289289
290+ PJ Fanning (pjfanning @github )
291+ * Contributed #744 : Limit size of exception message in BigDecimalParser
292+ (2.13 .3 )
293+
290294Ilya Golovin (ilgo0413 @github )
291295 * Contributed #684 : Add "JsonPointer#appendProperty" and "JsonPointer#appendIndex"
292296 (2.14 .0 )
Original file line number Diff line number Diff line change @@ -24,6 +24,11 @@ JSON library.
2424 floating - point values or not
2525 (contributed Doug R )
2626
27+ 2.13 .3 (not yet released )
28+
29+ #744 : Limit size of exception message in BigDecimalParser
30+ (contributed by @pjfanning ))
31+
27322.13 .2 (06 - Mar - 2022 )
2833
2934#732 : Update Maven wrapper
Original file line number Diff line number Diff line change 2121 */
2222public final class BigDecimalParser
2323{
24+ private final static int MAX_CHARS_TO_REPORT = 1000 ;
2425 private final char [] chars ;
2526
2627 BigDecimalParser (char [] chars ) {
@@ -51,7 +52,14 @@ public static BigDecimal parse(char[] chars) {
5152 if (desc == null ) {
5253 desc = "Not a valid number representation" ;
5354 }
54- throw new NumberFormatException ("Value \" " + new String (chars )
55+ String stringToReport ;
56+ if (chars .length <= MAX_CHARS_TO_REPORT ) {
57+ stringToReport = new String (chars );
58+ } else {
59+ stringToReport = new String (Arrays .copyOfRange (chars , 0 , MAX_CHARS_TO_REPORT ))
60+ + "(truncated, full length is " + chars .length + " chars)" ;
61+ }
62+ throw new NumberFormatException ("Value \" " + stringToReport
5563 + "\" can not be represented as `java.math.BigDecimal`, reason: " + desc );
5664 }
5765 }
Original file line number Diff line number Diff line change 1+ package com .fasterxml .jackson .core .io ;
2+
3+ public class BigDecimalParserTest extends com .fasterxml .jackson .core .BaseTest {
4+ public void testLongStringParse () {
5+ final int len = 1500 ;
6+ final StringBuilder sb = new StringBuilder (len );
7+ for (int i = 0 ; i < len ; i ++) {
8+ sb .append ("A" );
9+ }
10+ try {
11+ BigDecimalParser .parse (sb .toString ());
12+ fail ("expected NumberFormatException" );
13+ } catch (NumberFormatException nfe ) {
14+ assertTrue ("exception message starts as expected?" , nfe .getMessage ().startsWith ("Value \" AAAAA" ));
15+ assertTrue ("exception message value contains truncated" , nfe .getMessage ().contains ("truncated" ));
16+ }
17+ }
18+ }
You can’t perform that action at this time.
0 commit comments