sharanggupta opened a new pull request, #539: URL: https://github.com/apache/pdfbox/pull/539
Fixes [PDFBOX-6200](https://issues.apache.org/jira/browse/PDFBOX-6200) (and the same problem reported as [PDFBOX-6039](https://issues.apache.org/jira/browse/PDFBOX-6039)). `COSUpdateState.setOriginDocumentState()` links the document state to the managed object and to all its substructures by calling itself for each entry of a dictionary or an array and for the target of a dereferenced `COSObject`. A deeply nested structure therefore overflows the stack, which is what the DSS users signing large AutoCAD documents with an incremental save hit in PDFBOX-6200. As Michael Klink suggested on PDFBOX-6039, the recursion is replaced by a loop over an explicit stack (`ArrayDeque`) rather than a depth limit, so no structure is left without its document state. The traversal visits the same objects with the same rules: a state that already has an origin is skipped (which also stops at cycles), `update()` is called unless dereferencing, and the substructures are those of dictionaries, arrays and dereferenced indirect objects. Only the visiting order differs, which does not matter as each state is updated independently. **Test:** `TestCOSUpdateInfo.testSetOriginDocumentStateOfDeeplyNestedStructure` links a document state to a chain of 50,000 nested dictionaries, arrays and indirect objects and checks that the deepest one is linked and marked as updated. On `trunk` it fails with a `StackOverflowError` thrown by the recursive `setOriginDocumentState()` calls; with the change it passes. The `cos`, `pdfwriter` and `PDDocument` tests pass, and the full `pdfbox` module build passes locally. -- 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]
