Skip to content
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

BUG: Handle IndirectObject in media boxes #2460

Closed
wants to merge 4 commits into from

Conversation

SamStephens
Copy link

Fixes the bug where passing an IndirectObject to the constructor of FloatObject emitted a warning and resulting in a value of 0.0, rather than an exception being thrown.

When an IndirectObject is passed to the constructor of RectangleObject, unwrap that IndirectObject so the number it contains is used; this allows for PDFs with page dimensions that include IndirectObjects.

Fixes #2287

The FloatObject constructor swallowed all exceptions, which masked
issues where IndirectObject was incorrectly passed into the
constructor. Instead, follow the pattern NumberObject does, and
only swallow ValueError from malformed PDFs.
If an IndirectObject is passed as a parameter to the RectangleObject
constructor, unwrap it so we use the number/float it contains.
@SamStephens SamStephens changed the title Handle IndirectObject in media boxes BUG: Handle IndirectObject in media boxes Feb 19, 2024
Copy link

codecov bot commented Feb 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cc306ad) 94.43% compared to head (323e162) 94.43%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2460   +/-   ##
=======================================
  Coverage   94.43%   94.43%           
=======================================
  Files          49       49           
  Lines        8008     8019   +11     
  Branches     1616     1618    +2     
=======================================
+ Hits         7562     7573   +11     
  Misses        276      276           
  Partials      170      170           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Ensures we only go to a maximum depth, so a malicious PDF cannot
get us indefinitely stuck. Also introduces unit tests.
Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. LGTM.

pubpub-zz added a commit to pubpub-zz/pypdf that referenced this pull request Feb 20, 2024
@pubpub-zz
Copy link
Collaborator

I've proposed an alternative that should cover more cases
Can you have a review ?

stefan6419846 pushed a commit that referenced this pull request Feb 25, 2024
@stefan6419846
Copy link
Collaborator

Thanks for your proposal. I decided to go with #2464 which covers this issue in a more generic manner.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IndirectObject warnings from PdfReader#pages result in width of 0.0
3 participants