@@ -199,8 +199,14 @@ public class CsvDecoder
199
199
final protected static int NR_DOUBLE = 0x008 ;
200
200
final protected static int NR_BIGDECIMAL = 0x0010 ;
201
201
202
- // Also, we need some numeric constants
202
+ // Also, we need some numeric constants (copied from ParserBase)
203
203
204
+ final static BigInteger BI_MIN_INT = BigInteger .valueOf (Integer .MIN_VALUE );
205
+ final static BigInteger BI_MAX_INT = BigInteger .valueOf (Integer .MAX_VALUE );
206
+
207
+ final static BigInteger BI_MIN_LONG = BigInteger .valueOf (Long .MIN_VALUE );
208
+ final static BigInteger BI_MAX_LONG = BigInteger .valueOf (Long .MAX_VALUE );
209
+
204
210
final static BigDecimal BD_MIN_LONG = new BigDecimal (Long .MIN_VALUE );
205
211
final static BigDecimal BD_MAX_LONG = new BigDecimal (Long .MAX_VALUE );
206
212
@@ -1372,8 +1378,12 @@ protected void convertNumberToInt() throws IOException
1372
1378
}
1373
1379
_numberInt = result ;
1374
1380
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1375
- // !!! Should check for range...
1376
- _numberInt = _getBigInteger ().intValue ();
1381
+ final BigInteger bigInteger = _getBigInteger ();
1382
+ if (BI_MIN_INT .compareTo (bigInteger ) > 0
1383
+ || BI_MAX_INT .compareTo (bigInteger ) < 0 ) {
1384
+ reportOverflowInt ();
1385
+ }
1386
+ _numberInt = bigInteger .intValue ();
1377
1387
} else if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1378
1388
// Need to check boundaries
1379
1389
if (_numberDouble < MIN_INT_D || _numberDouble > MAX_INT_D ) {
@@ -1399,8 +1409,12 @@ protected void convertNumberToLong() throws IOException
1399
1409
if ((_numTypesValid & NR_INT ) != 0 ) {
1400
1410
_numberLong = _numberInt ;
1401
1411
} else if ((_numTypesValid & NR_BIGINT ) != 0 ) {
1402
- // !!! Should check for range...
1403
- _numberLong = _getBigInteger ().longValue ();
1412
+ final BigInteger bigInteger = _getBigInteger ();
1413
+ if (BI_MIN_LONG .compareTo (bigInteger ) > 0
1414
+ || BI_MAX_LONG .compareTo (bigInteger ) < 0 ) {
1415
+ reportOverflowLong ();
1416
+ }
1417
+ _numberLong = bigInteger .longValue ();
1404
1418
} else if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1405
1419
// Need to check boundaries
1406
1420
if (_numberDouble < MIN_LONG_D || _numberDouble > MAX_LONG_D ) {
@@ -1444,11 +1458,10 @@ protected void convertNumberToBigInteger()
1444
1458
protected void convertNumberToDouble ()
1445
1459
throws IOException
1446
1460
{
1447
- /* 05-Aug-2008, tatus: Important note: this MUST start with
1448
- * more accurate representations, since we don't know which
1449
- * value is the original one (others get generated when
1450
- * requested)
1451
- */
1461
+ // 05-Aug-2008, tatus: Important note: this MUST start with
1462
+ // more accurate representations, since we don't know which
1463
+ // value is the original one (others get generated when
1464
+ // requested)
1452
1465
1453
1466
if ((_numTypesValid & NR_BIGDECIMAL ) != 0 ) {
1454
1467
_numberDouble = _getBigDecimal ().doubleValue ();
@@ -1468,9 +1481,8 @@ protected void convertNumberToDouble()
1468
1481
protected void convertNumberToBigDecimal () throws IOException
1469
1482
{
1470
1483
if ((_numTypesValid & NR_DOUBLE ) != 0 ) {
1471
- /* Let's actually parse from String representation, to avoid
1472
- * rounding errors that non-decimal floating operations could incur
1473
- */
1484
+ // Let's actually parse from String representation, to avoid
1485
+ // rounding errors that non-decimal floating operations could incur
1474
1486
final String text = getText ();
1475
1487
_ioContext .streamReadConstraints ().validateFPLength (text .length ());
1476
1488
_numberBigDecimal = NumberInput .parseBigDecimal (
0 commit comments