sharanggupta commented on PR #539:
URL: https://github.com/apache/pdfbox/pull/539#issuecomment-6190444544

   The recursive version already has the equivalent of a visited set: 
`setOriginDocumentState()` returns at once when the state already has an origin 
document state, so each object is visited only once and cycles terminate, as 
with the set in `PageTree` and `Splitter`. The overflow is caused by depth, not 
by cycles. The method goes depth-first through every entry of every dictionary 
and array and every dereferenced object, so the stack depth is the length of 
the longest path through objects that have not been visited yet. In a document 
with many interlinked objects, like the AutoCAD file in PDFBOX-6200, that path 
can run to tens of thousands of objects even though none is visited twice.
   
   The test shows this: its chain of 50,000 nested objects has no cycle, and 
trunk still throws a `StackOverflowError` despite the visited check. A visited 
set doesn't bound the depth. Only an explicit stack does, or a depth limit as 
in the PDFBOX-6039 patch, which leaves objects without a state. The loop keeps 
the same visit-once check and only keeps the pending objects on the heap 
instead of the call stack.
   


-- 
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