Skip to content

ROB: Do not crash when the AcroForm entry is not a dictionary - #4029

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:acroform-not-a-dictionary
Aug 31, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:acroform-not-a-dictionary

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

If a PDF has a /AcroForm entry that is not a dictionary, reading the form fields crashes. The code assumes the entry is a dictionary and looks for /Fields inside it. If it is a number, a string or an array instead, that check fails with a plain Python error.

get_fields already returns None when there is no /AcroForm at all, so now an entry it cannot read does the same thing and logs a warning.

This is the same problem as #4019, one level higher — that one fixed the /Fields array, this one fixes the /AcroForm entry itself.

@stefan6419846 stefan6419846 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please check the test failure (test_workflows.py::test_get_fields_warns).

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Good catch, that was mine. The old cast let a null entry through to the existing None check, but calling get_object() on it raised AttributeError. A damaged file can leave the key present with no value, which I had not tested for.

Fixed so a null entry is still treated as absent and only a wrong type is reported. I also added a test for the null case.

@codecov

codecov Bot commented Aug 28, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.03%. Comparing base (ea6ff22) to head (debec8f).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4029   +/-   ##
=======================================
  Coverage   98.03%   98.03%           
=======================================
  Files          57       57           
  Lines       11201    11206    +5     
  Branches     2108     2109    +1     
=======================================
+ Hits        10981    10986    +5     
  Misses        123      123           
  Partials       97       97           

☔ 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.

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Fixed on the 28th - a damaged file can leave the key present with no value, and calling get_object() on it raised AttributeError. Null is treated as absent again, and there is a test for it now.

Comment thread tests/test_doc_common.py Resolved
@RavSinghChandan
RavSinghChandan force-pushed the acroform-not-a-dictionary branch from f67856d to debec8f Compare August 30, 2026 14:04
@stefan6419846
stefan6419846 merged commit 2f3ed6b into py-pdf:main Aug 31, 2026
26 of 34 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