Skip to content

Commit

Permalink
Tolerate AcroForms without a Fields entry
Browse files Browse the repository at this point in the history
Fixes #403
  • Loading branch information
MatthiasValvekens committed Mar 21, 2024
1 parent 5a9d8eb commit 6d4cde9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
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

0 comments on commit 6d4cde9

Please sign in to comment.