Skip to content

Skip /Annots entries that have no valid /Subtype - #128

Merged
0xabu merged 2 commits into
0xabu:mainfrom
RavSinghChandan:skip-annots-entries-without-subtype
Nov 10, 2026
Merged

0xabu merged 2 commits into
0xabu:mainfrom
RavSinghChandan:skip-annots-entries-without-subtype

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

When a page's /Annots array refers to a dictionary that isn't an annotation, pdfannots stops with:

  File "pdfannots/__init__.py", line 57, in _mkannotation
    assert isinstance(subtype, PSLiteral)
AssertionError

I hit this with tests/resources/test_2861.pdf from PyMuPDF (from pymupdf/PyMuPDF#2861), a published paper. Its first page's /Annots lists a link's action dictionary (/S /URI) and its border array next to the two /Link annotations. The border array already gives an empty dict and is skipped, but the action dictionary reaches _mkannotation() without a /Subtype.

_mkannotation() now logs a warning and returns None for such an entry, like it does for an unsupported subtype, and the rest of the page is read.

I didn't add the paper itself as a test file (copyright, and an author's e-mail address in it). tests/annots-entries-without-subtype.pdf has the same structure, made with pypdf: a border array, an action dictionary and a Text annotation in /Annots. The AnnotsEntriesWithoutSubtype test checks that the Text annotation is extracted; it fails on main. pytest tests.py, mypy ., flake8 pdfannots tests.py and autopep8 --diff pass.

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

@0xabu
0xabu merged commit 4a6c71e into 0xabu:main Nov 10, 2026
7 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