Andreas Lehmkühler created PDFBOX-6097:
------------------------------------------

             Summary: Avoid StackOverflow when collecting indirect object keys
                 Key: PDFBOX-6097
                 URL: https://issues.apache.org/jira/browse/PDFBOX-6097
             Project: PDFBox
          Issue Type: Bug
          Components: PDModel
    Affects Versions: 3.0.5 PDFBox, 4.0.0
            Reporter: Andreas Lehmkühler
            Assignee: Andreas Lehmkühler


Kiran Kandel reports an issue on [Stackoverflow | 
https://stackoverflow.com/questions/79815248/stack-overflow-when-collecting-indirect-object-keys-from-recursive-pdf-structure]
The following code sample results in a StackoverflowException

{code}
PDDocument document = new PDDocument();
PDPage page = new PDPage(PDRectangle.A4);
// Create AcroForm
PDAcroForm acroForm = new PDAcroForm(document);
document.getDocumentCatalog().setAcroForm(acroForm);

// Create a single text field
PDTextField textField = new PDTextField(acroForm);
textField.setPartialName("testField");
PDAnnotationWidget widget = textField.getWidgets().get(0);
widget.setRectangle(new PDRectangle(100, 700, 200, 20));
widget.setPage(page);
page.getAnnotations().add(widget);
acroForm.getFields().add(textField);

// Adding page AFTER creating form fields causes StackOverflowError
document.addPage(page);

document.save("output.pdf");
document.close();
{code}

[~tilman] already found the reason for the issue. The method in question 
detects and skips parent references to avoid recursion. This works fine as long 
as the key PARENT is used. In combination with annotations the abbreviated key 
P is used but isn't detected.







--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to