Skip to content

Keep FastDateParser numeric parse from throwing on int overflow#1741

Merged
garydgregory merged 1 commit into
apache:masterfrom
alhudz:fastdateparser-numeric-overflow
Jul 4, 2026
Merged

Keep FastDateParser numeric parse from throwing on int overflow#1741
garydgregory merged 1 commit into
apache:masterfrom
alhudz:fastdateparser-numeric-overflow

Conversation

@alhudz

@alhudz alhudz commented Jul 4, 2026

Copy link
Copy Markdown
Contributor

Repro: parse an untrusted date whose numeric field is a digit run that overflows int, e.g. FastDateFormat.getInstance("yyyy").parse("99999999999"), or getInstance("yyyy").parseObject("99999999999", new ParsePosition(0)).
Cause: NumberStrategy.parse scans an unbounded run of digits for a trailing or standalone numeric field (its maxWidth is 0) and passes the whole run to Integer.parseInt. A run that overflows int makes parseInt throw NumberFormatException, which escapes uncaught, so parse(String) throws NumberFormatException rather than the declared ParseException, and the ParsePosition overloads (parse, parseObject) throw instead of returning null with an error index as the java.text.Format contract requires.
Fix: catch the overflow inside NumberStrategy.parse and signal a parse failure the same way the existing empty-digit branch already does (setErrorIndex then return false), so the field is simply unparseable instead of crashing the parser. Valid inputs are unchanged and it is the only Integer.parseInt in the class.

@garydgregory garydgregory changed the title keep FastDateParser numeric parse from throwing on int overflow Keep FastDateParser numeric parse from throwing on int overflow Jul 4, 2026
@garydgregory garydgregory merged commit d4b4d8c into apache:master Jul 4, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants