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

   `PackagePartCollection.put` checks rule M1.11 for every zip entry while 
`OPCPackage.open` loads a package, before any application code sees the 
document. It rebuilt each slash-delimited prefix of the part name as a new 
string and looked it up in the registered-name set, so a name with k segments 
costs O(k * length): a 1.2 MB package with 10 entries named `a/a/a/.../a/N.xml` 
(about 30,000 segments each, inside the 65,535-byte zip name limit) takes about 
17 s to open from a stream and 24 s from a file on JDK 21, and the default 
1000-entry limit leaves room for roughly half an hour of CPU per file. That 
makes it an algorithmic-complexity DoS (CWE-407) reachable from any OOXML 
upload.
   
   A prefix can only be in the set when a registered name has exactly its 
length, so the collection now keeps a count of name lengths next to the set and 
only builds a prefix in that case, which gives the same answers as before 
(checked against the old code over all names up to length 6 built from `/`, `a` 
and `b`, every ordered pair of them and random put/remove sequences, 3.6M 
operations without a mismatch). The same package now opens in about 0.13 s from 
a stream and 0.7 s from a file, and `testDeeplyNestedPartNames` times out after 
10 s before the change. Keeping the check in the collection covers both zip 
loading and `createPart`; the openxml4j, xwpf, xslf, ooxml, poifs, xssf and ss 
suites pass apart from `stackoverflow23114397` and one 
`TestSXSSFSheetAutoSizeColumn` case, which depend on font metrics and fail on 
my machine on unpatched trunk 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: [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]

Reply via email to