Skip to content

fix #426: Flash reads AES PDFs and guards lazy PyPDF2 failures - #435

Open
xinyao-li wants to merge 1 commit into
VectifyAI:mainfrom
xinyao-li:issue-426
Open

fix #426: Flash reads AES PDFs and guards lazy PyPDF2 failures#435
xinyao-li wants to merge 1 commit into
VectifyAI:mainfrom
xinyao-li:issue-426

Conversation

@xinyao-li

@xinyao-li xinyao-li commented Aug 27, 2026

Copy link
Copy Markdown

Add PyCryptodome as PyPDF2's AES backend and force page-tree resolution inside the existing guarded open so an unavailable secondary parser falls back to PDFium instead of crashing.

Summary

  • add PyCryptodome as PyPDF2's AES backend
  • eagerly resolve the PyPDF2 page tree inside the existing guarded open
  • fall back to the PDFium-only channel if PyPDF2 cannot read the document

Fixes #426.

Root cause

PyPDF2 parses the page tree lazily. PdfReader() succeeded inside the
existing try/except, but len(reader.pages) later raised DependencyError
outside that guard while decrypting an AES-encrypted object stream.

Resolving and caching the page count in _PdfDoc.__init__ keeps that lazy
failure inside the existing guarded open used by both sequential and
parallel parsing.

Test plan

  • reproduced the original failure with an AES-128, empty-user-password PDF
  • verified AES-128 and AES-256 PDFs parse after installing PyCryptodome
  • verified PDFium-only fallback without PyCryptodome in sequential and
    parallel parsing
  • added regression tests for the lazy PyPDF2 failure
  • 386 passed, 53 skipped

Add PyCryptodome as PyPDF2's AES backend and force page-tree resolution inside the existing guarded open so an unavailable secondary parser falls back to PDFium instead of crashing.

Co-authored-by: Cursor <cursoragent@cursor.com>
@xinyao-li xinyao-li changed the title fix: Flash reads AES PDFs and guards lazy PyPDF2 failures fix #426: Flash reads AES PDFs and guards lazy PyPDF2 failures Aug 27, 2026
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.

PyPDF2.errors.DependencyError: PyCryptodome is required for AES algorithm — crash on permission-only-encrypted PDFs (Flash preview)

1 participant