ROB: guard missing /AP appearance state in button form fields#3893
ROB: guard missing /AP appearance state in button form fields#3893metsw24-max wants to merge 2 commits into
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3893 +/- ##
==========================================
+ Coverage 97.83% 97.87% +0.03%
==========================================
Files 55 57 +2
Lines 10609 10753 +144
Branches 1985 2010 +25
==========================================
+ Hits 10379 10524 +145
Misses 127 127
+ Partials 103 102 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
9cc752c to
b454298
Compare
|
Pushed an update. The helper now lives on PdfDocCommon as a staticmethod and raises PdfReadError for a malformed appearance (non-dictionary /AP, or a missing/non-dictionary /N) rather than skipping silently, so the public get_fields() reports a documented error instead of leaking a bare KeyError. Tests updated to assert the raise and to use an exact /States comparison. |
| """Return the /N normal-appearance sub-dictionary of an /AP entry.""" | ||
| appearance = appearance.get_object() | ||
| if not isinstance(appearance, DictionaryObject): | ||
| raise PdfReadError(f"Expected appearance dictionary, got {appearance!r}") |
There was a problem hiding this comment.
This line is uncovered. Please check.
There was a problem hiding this comment.
Good catch. Added a checkbox case with a non-dictionary /AP, so that raise is exercised now and the branch is covered.
|
any update? |
|
See #3900. |
Uncaught KeyError reading button field appearance states
_build_fieldcollects the checkbox and radio appearance states from/AP/N, but it assumes both are present and are dictionaries, so a button field whose/APhas no/N, or a radio kid with no/AP//N, raises an uncaughtKeyErrorout of the publicreader.get_fields()on a malformed document.Both lookups now go through a small
_normal_appearancehelper onPdfDocCommon./Nis required in an appearance dictionary, so a malformed appearance (a non-dictionary/AP, or a missing or non-dictionary/N) now raises the documentedPdfReadErrorrather than a bareKeyError. Valid forms are unchanged.