Skip to content

ROB: Do not crash when the XFA entry is not a well-formed array - #4064

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:xfa-not-a-well-formed-array
Sep 10, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:xfa-not-a-well-formed-array

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

reader.xfa iterates /XFA in tag/value pairs after casting it to an array, so a
malformed entry crashes rather than being reported.

Two cases:

  • /XFA that is not an array at all raises "argument of type 'NumberObject' is
    not iterable", or exhausts the iterator for a string. The spec also permits a
    stream here, which the pairwise walk cannot consume.
  • An array with an odd number of elements — a trailing tag with no value —
    raises StopIteration out of the property, because next(i) has nothing left.

The entry is now checked before iterating, warning and returning no XFA data
the way an absent /AcroForm does, and the paired read tolerates a missing
value instead of raising.

Offline suite passes, 1318 tests. tests/test_reader.py::test_read_pdf15_xref_stream
fails here with FileNotFoundError both with and without this change, so I could
not verify against the downloaded corpus.

Used Claude (Opus) to help locate and patch this; I reviewed and tested the change.

@codecov

codecov Bot commented Sep 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.11%. Comparing base (7bb71dd) to head (416a0c0).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4064   +/-   ##
=======================================
  Coverage   98.10%   98.11%           
=======================================
  Files          59       59           
  Lines       11477    11480    +3     
  Branches     2148     2149    +1     
=======================================
+ Hits        11260    11264    +4     
  Misses        122      122           
+ Partials       95       94    -1     

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

@stefan6419846
stefan6419846 merged commit 3f7bc19 into py-pdf:main Sep 10, 2026
25 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