-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ROB: Handle /Pages node without /Kids during flattening #3825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1184,7 +1184,15 @@ def _flatten( | |||||
| if attr in pages: | ||||||
| inherit[attr] = pages[attr] | ||||||
| pages_reference = getattr(pages, "indirect_reference", object()) | ||||||
| for page in cast(ArrayObject, pages[PagesAttributes.KIDS]): | ||||||
| # A malformed /Pages node may be missing /Kids (for example a page | ||||||
| # tree advertising "/Count 0" without any children). Treat it as | ||||||
| # having no kids instead of raising a bare KeyError here (#3811). | ||||||
| kids = ( | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This can be written in a simpler way:
Suggested change
|
||||||
| pages[PagesAttributes.KIDS] | ||||||
| if PagesAttributes.KIDS in pages | ||||||
| else ArrayObject() | ||||||
| ) | ||||||
| for page in cast(ArrayObject, kids): | ||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we are at it (and although not required here), I would recommend replacing this cast and increase the resilience here. What I mean is that we should use an empty |
||||||
| if getattr(page, "indirect_reference", object()) == pages_reference: | ||||||
| raise PdfReadError("Detected cyclic page references.") | ||||||
|
|
||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think that this comment contributes enough to be useful here.