naruto-lgtm opened a new pull request, #1577: URL: https://github.com/apache/poi/pull/1577
Repro: a docx whose document part has n hyperlink relationships and n `w:hyperlink` elements with an `r:id` that is not one of them. With n = 20,000 (172 KB) it loads in 0.2 s, then `XWPFWordExtractor` with `setFetchHyperlinks(true)` takes 114 s (32 s at 10,000, 7.4 s at 5,000). Any caller that resolves `XWPFHyperlinkRun.getHyperlink` hits the same path. Cause: `XWPFDocument.getHyperlinkByID` scans the hyperlink list and, on a miss, rebuilds it from every relationship of the document part before scanning again, so the cost is unknown ids x relationships, both chosen by the file (algorithmic-complexity DoS, CWE-407). Known ids also pay a linear scan each. Fix: index the links by id, and on a miss look up only that relationship on the package part and add it if it is a hyperlink, so links added after loading (`createHyperlinkRun`, covered by `testAddHyperlink`) still resolve without the rebuild. The one behavioural difference is that a miss no longer refreshes `getHyperlinks()` as a side effect, so a link whose relationship was removed stays listed, as it already did until the first miss. The reproducer now extracts in 0.22 s; `TestXWPFDocument.testUnknownHyperlinkIds` times out on trunk and passes here, and the xwpf, extractor and dsig test suites pass. -- 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]
