Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tolerate AcroForms without a Fields entry #404

Merged
merged 1 commit into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyhanko/sign/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ def prepare_sig_field(
try:
fields = form['/Fields']
except KeyError:
raise PdfError('/AcroForm has no /Fields')
fields = form['/Fields'] = generic.ArrayObject()

candidates = enumerate_sig_fields_in(
fields, with_name=sig_field_name, refs_seen=set()
Expand Down
9 changes: 5 additions & 4 deletions pyhanko_tests/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,6 @@ def test_append_sig_field_acro_update():

def test_append_acroform_no_fields():
w = PdfFileWriter()
# Technically, this is not standards-compliant, but our routine
# shouldn't care
w.root['/AcroForm'] = generic.DictionaryObject()
w.insert_page(simple_page(w, 'Hello world'))
out = BytesIO()
Expand All @@ -449,8 +447,11 @@ def test_append_acroform_no_fields():

sp = fields.SigFieldSpec('InvisibleSig')
w = IncrementalPdfFileWriter(out)
with pytest.raises(PdfError, match="has no /Fields"):
fields.append_signature_field(w, sp)
fields.append_signature_field(w, sp)
w.write_in_place()

r = PdfFileReader(out)
assert len(r.root['/AcroForm']['/Fields']) == 1


def test_append_acroform_reference_broken_nonstrict():
Expand Down
Loading