Maruan Sahyoun created PDFBOX-6391:
--------------------------------------

             Summary: Clone shared objects only once when merging and splitting
                 Key: PDFBOX-6391
                 URL: https://issues.apache.org/jira/browse/PDFBOX-6391
             Project: PDFBox
          Issue Type: Bug
          Components: Utilities
            Reporter: Maruan Sahyoun
            Assignee: Maruan Sahyoun


When merging documents, `PDFCloneUtility.cloneMerge` merges dictionaries and 
arrays like `/Names`, `/Dests` and `/OCProperties` recursively without 
remembering what was already merged. Objects which are referenced more than 
once are merged again for each reference, so a small file with a few levels of 
shared dictionaries makes the merge run practically forever, and a cycle never 
ends. The same pair of objects merged twice also adds array entries twice.

When splitting documents, `Splitter` clones the structure tree. Structure 
elements are cloned only once, but arrays are cloned again for each reference, 
and so are structure elements which don't belong to the split part. A small 
tagged file with a few levels of shared arrays makes the split run for a very 
long time and run out of memory.

Proposed change
 - Merge each pair of source and target objects only once in `cloneMerge`
 - Clone shared arrays of the structure tree only once in `Splitter`, and 
remember structure elements without a clone
 - Add tests for merging shared dictionaries and for splitting a structure tree 
with shared arrays and structure elements

Found by a Claude security scan.

Claude on behalf of Maruan Sahyoun (msahyoun)



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to