Skip to content

ROB: Do not crash on merging pages whose resources are not a dictionary - #4350

Merged
stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:merge-page-resources-not-a-dictionary
Nov 10, 2026
Merged

stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:merge-page-resources-not-a-dictionary

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

page.merge_page(page2) raised TypeError: argument of type 'NumberObject' is not iterable when the /Resources of either page is a number, array, string or null, for example a page read from a malformed file.

The malformed resources are now treated as empty, like #4272 and #4329 do: "Page resources are not a dictionary: ..." is logged (no warning for null), and the resources of the other page are still merged. When the page that receives the merge has malformed resources, they are replaced by a new dictionary.

Added test_merge_page__resources_are_not_a_dictionary, covering both pages and a page read back with PdfReader; it fails on main

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.80%. Comparing base (b63ad4e) to head (491b3cb).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4350   +/-   ##
=======================================
  Coverage   98.80%   98.80%           
=======================================
  Files          59       59           
  Lines       12183    12184    +1     
  Branches     2316     2316           
=======================================
+ Hits        12037    12038    +1     
  Misses         71       71           
  Partials       75       75           

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pypdf/_page.py Resolved
Comment thread tests/test_page.py Resolved
@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Good point: "own" was meant as "not inherited from the parent pages", which is what merge_page has always used. I removed the second helper; merge_page now calls _get_page_resources(page, inherit=False), so the name states the difference. Also applied your docstring suggestion.

@stefan6419846
stefan6419846 merged commit 8402b00 into py-pdf:main Nov 10, 2026
39 of 76 checks passed
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.

2 participants