You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by "naruto-lgtm (via GitHub)" <gi...@apache.org> on 2026/10/18 07:07:22 UTC

[PR] DataFormatter: avoid backtracking blowup in rangeConditionalPattern [poi]

naruto-lgtm opened a new pull request, #1436:
URL: https://github.com/apache/poi/pull/1436

   Repro: `new DataFormatter().formatRawCellContents(1.5, -1, "[<" + "1".repeat(20_000))` takes about 15 s, and about 12 s again on every later call with the same format. The format string can come straight from styles.xml or an HSSF FORMAT record, and a 20 KB run of digits compresses to almost nothing inside an .xlsx, so one style applied to many cells makes text extraction take hours (a ReDoS, CWE-1333).
   Cause: in `rangeConditionalPattern` the constant `-?[0-9]*\.?[0-9]+` can split a run of digits between `[0-9]*` and `[0-9]+` in every possible way, so when the closing `]` is missing the regex retries each split. `getFormat` runs this `find()` before the format cache, so the cost is paid per cell, not per format.
   Fix: `-?(?:[0-9]*\.)?[0-9]+` accepts the same strings with only one way to match a digit run. I checked old and new patterns against each other over all 5.4M strings up to length 7 built from `[<>=1.- ]`, and they give identical matches and groups.
   
   | format length | before (1st / 2nd call) | after (1st / 2nd call) |
   |---|---|---|
   | 4,002 | 605 ms / 449 ms | 3 ms / 1 ms |
   | 20,002 | 15,552 ms / 12,306 ms | 38 ms / 12 ms |
   | 100,002 | not run | 69 ms / 55 ms |
   
   `testConditionalRangeWithLongNumber` times out after 10 s before the change and passes after. `TestDataFormatter`, the `ss` and `hssf.usermodel` suites, `TestDataFormatterAgainstExcel`, `TestCellFormatPart`, `TestXSSFDataFormat` and `:poi:forbiddenApis` pass. (`TestDateSerialRange.testEdgesOfTheRange` fails on trunk without this change too.)
   


-- 
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: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] DataFormatter: avoid backtracking blowup in rangeConditionalPattern [poi]

Posted by "naruto-lgtm (via GitHub)" <gi...@apache.org>.
naruto-lgtm commented on PR #1436:
URL: https://github.com/apache/poi/pull/1436#issuecomment-6254782271

   Thanks for merging this. The other spots I'd look at first are the patterns that run before any caching, since that's what turned a per-format cost into a per-cell one here.


-- 
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: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] DataFormatter: avoid backtracking blowup in rangeConditionalPattern [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning commented on PR #1436:
URL: https://github.com/apache/poi/pull/1436#issuecomment-6247726904

   merged - thanks
   
   There are possibly some more regexes that can act like this. I'm doing a review.


-- 
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: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org


Re: [PR] DataFormatter: avoid backtracking blowup in rangeConditionalPattern [poi]

Posted by "pjfanning (via GitHub)" <gi...@apache.org>.
pjfanning merged PR #1436:
URL: https://github.com/apache/poi/pull/1436


-- 
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: dev-unsubscribe@poi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org