Repository navigation
ROB: Do not crash on removing objects when the resources are not a dictionary - #4329
Merged
stefan6419846 merged 2 commits intoNov 2, 2026
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4329 +/- ##
=======================================
Coverage 98.79% 98.79%
=======================================
Files 59 59
Lines 12114 12120 +6
Branches 2304 2308 +4
=======================================
+ Hits 11968 11974 +6
Misses 70 70
Partials 76 76 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
stefan6419846
approved these changes
Nov 2, 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.
writer.remove_images()andwriter.remove_text()raisedTypeError(for example'NumberObject' object is not subscriptable) when a page's/Resourcesis a number, array or string, andAttributeError: 'NumberObject' object has no attribute 'items'when its/XObjectentry is a number._remove_objects_from_page__clean_forms()looked up/Resources->/XObjectand only caughtKeyError.It now handles them like #4272 does for
page.images: it logs "Resources are not a dictionary: ..." or "XObject resources are not a dictionary: ...", treats the page as having no XObject resources and still removes the inline images or the text in the content stream. A null/Resourcesor/XObjectis treated as missing, without a warning.Added
test_remove_objects__resources_are_not_a_dictionary, covering both methods with number, array, string and null resources and number and null/XObjectentries