pjfanning opened a new pull request, #1443:
URL: https://github.com/apache/poi/pull/1443
Follow-up to the regex backtracking fixes (#1437, #1440).
Repro: with `setUse4DigitYearsInAllDateFormats(true)`, formatting a cell
whose format is `"yy/".repeat(50_000)` throws `StackOverflowError`. The format
string can come from styles.xml or an HSSF FORMAT record.
Cause: `adjustTo4DigitYearsIfConfigured` recursed once per `yy`. Each call
also ran `indexOf("yyy")` and `indexOf("yyyy")` over the whole rest of the
format and copied it with `substring`.
Fix: a loop over the `yy` occurrences with `startsWith` checks at each one.
As before:
- `yyyy` is kept as it is.
- `yy` becomes `yyyy`.
- A `yyy` leaves the rest of the format unchanged.
Equivalence: old and new give identical output for all 7.2M strings up to
length 14 over `y`, `Y`, `/`. The new version takes about 1 ms on 150k chars.
Tests: added `testAdjustTo4DigitYearsWithLongFormat`, which throws
`StackOverflowError` before the change and passes after, and a `yy/yyy/yy` case
for the existing 3-digit-year behaviour. `TestDataFormatter` and
`TestHSSFDataFormatter` pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]