Repository navigation
ROB: Do not crash on images when the resources are not a dictionary - #4272
Merged
stefan6419846 merged 3 commits intoOct 31, 2026
Merged
stefan6419846 merged 3 commits into
stefan6419846 merged 3 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4272 +/- ##
=======================================
Coverage 98.65% 98.65%
=======================================
Files 59 59
Lines 11957 11962 +5
Branches 2267 2270 +3
=======================================
+ Hits 11796 11801 +5
Misses 84 84
Partials 77 77 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stefan6419846
requested changes
Oct 29, 2026
stefan6419846
left a comment
Collaborator
There was a problem hiding this comment.
Please review the merge conflict.
Check the resources type in _get_image instead of catching TypeError.
Contributor
Author
|
Only when an inline image ( |
Contributor
Author
|
Thanks for the review. I have resolved the merge conflict. |
stefan6419846
approved these changes
Oct 31, 2026
This was referenced Oct 31, 2026
This was referenced Nov 4, 2026
AP24110011695
added a commit
to AP24110011695/pypdf
that referenced
this pull request
Nov 4, 2026
_get_fonts_walk and the inline-image color-space lookup checked the presence of /Resources but not its type, raising TypeError when the value is not a dictionary. The same class was fixed for images (py-pdf#4272) and for removing objects (py-pdf#4329); these two siblings follow the same pattern: warn and treat as an empty dictionary, keeping the intended PdfReadError for unresolvable color-space names.
AP24110011695
added a commit
to AP24110011695/pypdf
that referenced
this pull request
Nov 9, 2026
_get_fonts_walk and the inline-image color-space lookup checked the presence of /Resources but not its type, raising TypeError when the value is not a dictionary. The same class was fixed for images (py-pdf#4272) and for removing objects (py-pdf#4329); these two siblings follow the same pattern: warn and treat as an empty dictionary, keeping the intended PdfReadError for unresolvable color-space names.
stefan6419846
pushed a commit
that referenced
this pull request
Nov 10, 2026
* ROB: Guard the remaining non-dictionary /Resources accesses _get_fonts_walk and the inline-image color-space lookup checked the presence of /Resources but not its type, raising TypeError when the value is not a dictionary. The same class was fixed for images (#4272) and for removing objects (#4329); these two siblings follow the same pattern: warn and treat as an empty dictionary, keeping the intended PdfReadError for unresolvable color-space names. * TST: Cover the resolution and null branches of the non-dictionary /Resources guards The inline-image color-space lookup was only tested on its short-circuit path (empty resources): the membership check and the return of the resolved color space had no coverage. /Resources that resolve to null skip the warning by design; pin that too. * fix: end test files with a single newline (pre-commit end-of-file hook) Signed-off-by: Ayush Kumar Saha <[email protected]> * MAINT: Apply the review suggestions Walrus operator for the color-space lookup, house test naming, anchored regex match, and a trimmed docstring. --------- Signed-off-by: Ayush Kumar Saha <[email protected]> Co-authored-by: Ayush Kumar Saha <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
page.imagesraisedTypeError: argument of type 'NumberObject' is not iterablewhen a page's/Resourcesis not a dictionary, from the/XObjectmembership test in_get_ids_image(). #4030 made a malformed/XObjectentry warn and return no images; this does the same one level up._get_ids_image()now logs "Resources are not a dictionary: ..." and treats the page as having no XObject resources, so inline images are still listed._get_image()also caught onlyKeyErrorwhen looking up/XObject, so reading such an inline image raised the sameTypeError; it now catchesTypeErrortoo. Addedtest_images__resources_are_not_a_dictionary(number, array and string cases, as intest_images__xobject_is_not_a_dictionary) and a test that the inline image is still returned.