fix: recursively traverse parent chain for inherited MediaBox #204
+36
−16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
PDF specification (sec 7.7.3.4, p 80) allows
/MediaBoxto be inherited from any ancestor in the page tree, not just the immediate parent. The previous fix in v4.7.1 only checked one level of parent, which failed for PDFs where/MediaBoxis defined at the grandparent level or higher (common in multi-level page trees).Problem
Certain valid PDFs fail with:
These PDFs have
/MediaBoxdefined at the root of the page tree (e.g., grandparent), not on individual pages or their immediate parents.Example PDF Structure (EU-lex document)
Solution
Recursively traverse the parent chain (up to 10 levels to prevent infinite loops in malformed PDFs) until
/MediaBoxis found or the root is reached.Testing
deep-mediabox-inheritance.pdf(EU-lex document with MediaBox at grandparent level)Fixes
Fixes #175
Signed-off-by: Sam Quigley sq@emerose.com