[
https://issues.apache.org/jira/browse/PDFBOX-6318?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18148178#comment-18148178
]
Tilman Hausherr edited comment on PDFBOX-6318 at 11/20/26, 2:33 PM:
--------------------------------------------------------------------
I think adding doesn't need that loop at all because it is inserted at the top,
but for now I won't change that unless I get a second opinion. This part was
written in PDFBOX-2423; prior to that PDFBox would go through the whole tree. I
suspect that "update ancestor counts" was written for removal first and then
copied & pasted to adding. I'll go with the "visited" suggestion.
[https://svn.apache.org/viewvc/?view=revision&revision=1634252]
was (Author: tilman):
I think adding doesn't need that loop at all because it is inserted at the top,
but for now I won't change that unless I get a second opinion. This part was
written in PDFBOX-2423; prior to that PDFBox would go through the whole tree. I
suspect that "update ancestor counts" was written for removal first and then
copied & pasted to adding. I'll go with the visited suggestion.
https://svn.apache.org/viewvc/?view=revision&revision=1634252
> PDPageTree.add() and remove() loop forever when the page tree has a /Parent
> cycle
> ---------------------------------------------------------------------------------
>
> Key: PDFBOX-6318
> URL: https://issues.apache.org/jira/browse/PDFBOX-6318
> Project: PDFBox
> Issue Type: Bug
> Components: PDModel
> Affects Versions: 3.0.8 PDFBox, 4.0.0
> Reporter: Martin Mirchev
> Priority: Major
> Attachments: pages-parent-self.pdf
>
>
> {{PDPageTree.add()}}, {{remove()}} and {{increaseParents()}} (used by
> {{insertBefore()}}/{{insertAfter()}}) update the {{/Count}} of every ancestor
> by following {{/Parent}} until it is null. If the chain has a cycle they
> never return.
> Attached {{pages-parent-self.pdf}} has a root {{Pages}} node whose
> {{/Parent}} points to itself. It loads, {{getNumberOfPages()}} returns 2, but
> {{doc.addPage(new PDPage())}} and {{doc.removePage(0)}} never return (thread
> still in {{PDPageTree.add}} / {{remove}} after 30 s; trunk bd0c9c0, 3/3
> runs). The same file without the cycle works.
> PDFBOX-3953 and PDFBOX-6040 handled cycles when reading the tree; these
> update loops have no such check. Stopping at the root ({{this.root}}) or
> keeping a set of visited nodes would avoid it.
> This issue was found by an LLM-assisted tool and verified manually.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]