mirror of
https://github.com/unicode-org/icu.git
synced 2025-04-21 12:40:02 +00:00
ICU-7480 Limit maximum integer parsed by DateNumberFormat to prevent overflow. Setting the limit is safe for this usage, because maximum number used by SimpleDateFormat is int and the limit is almost max long.
X-SVN-Rev: 27945
This commit is contained in:
parent
cf562954d7
commit
a9d071ce6d
2 changed files with 21 additions and 3 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2007-2009, International Business Machines
|
||||
* Copyright (C) 2007-2010, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*******************************************************************************
|
||||
*/
|
||||
|
@ -36,7 +36,7 @@ public final class DateNumberFormat extends NumberFormat {
|
|||
|
||||
private int maxIntDigits;
|
||||
private int minIntDigits;
|
||||
|
||||
|
||||
public DateNumberFormat(ULocale loc, char zeroDigitIn) {
|
||||
initialize(loc,zeroDigitIn);
|
||||
}
|
||||
|
@ -152,6 +152,8 @@ public final class DateNumberFormat extends NumberFormat {
|
|||
/*
|
||||
* Note: This method only parse integer numbers which can be represented by long
|
||||
*/
|
||||
private static final long PARSE_THRESHOLD = 922337203685477579L; // (Long.MAX_VALUE / 10) - 1
|
||||
|
||||
public Number parse(String text, ParsePosition parsePosition) {
|
||||
long num = 0;
|
||||
boolean sawNumber = false;
|
||||
|
@ -170,7 +172,7 @@ public final class DateNumberFormat extends NumberFormat {
|
|||
if (digit < 0 || 9 < digit) {
|
||||
digit = UCharacter.digit(ch);
|
||||
}
|
||||
if (0 <= digit && digit <= 9) {
|
||||
if (0 <= digit && digit <= 9 && num < PARSE_THRESHOLD) {
|
||||
sawNumber = true;
|
||||
num = num * 10 + digit;
|
||||
} else {
|
||||
|
|
|
@ -3701,4 +3701,20 @@ public class DateFormatTest extends com.ibm.icu.dev.test.TestFmwk {
|
|||
};
|
||||
expect(DATA, new Locale("en", "", ""));
|
||||
}
|
||||
|
||||
/*
|
||||
* Test case for very long contiguous numeric patterns (ticket#7480)
|
||||
*/
|
||||
public void TestLongContiguousNumericPattern() {
|
||||
String DATA[] = {
|
||||
"yyyy-MM-dd HH:mm:ss.SSS",
|
||||
|
||||
"yyyyMMddHHmmssSSSSSS", "fp", "2010-04-16 12:23:34.456",
|
||||
"20100416122334456000", "2010-04-16 12:23:34.456",
|
||||
|
||||
"yyyyyyMMddHHHHmmmmssssSSSSSS", "fp", "2010-04-16 12:23:34.456",
|
||||
"0020100416001200230034456000", "2010-04-16 12:23:34.456",
|
||||
};
|
||||
expect(DATA, new Locale("en", "", ""));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue