fix(pdf_reader): Auto-try blank password for encrypted PDFs without password #5160
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix: Auto-try blank password for encrypted PDFs without password
Problem
Many PDF files are technically "encrypted" but don't require an actual password - they just need an empty string to decrypt. This is standard behavior in PDF viewers (Adobe, Preview, etc.) and other PDF libraries (PyPDF2, pikepdf, etc.).
Currently, agno's
PDFReaderfails immediately when encountering such PDFs, causing the "zombie document bug":Why Can't Users Just Pass
password=""?Three blockers prevent this:
S3Reader hardcodes
PDFReader()(line 62 in s3_reader.py):No password parameter is passed, even if S3Reader accepted one!
The
oroperator bug (line 237 in pdf_reader.py):If you pass
password="", it's treated as False and falls through toself.password! Empty strings are falsy in Python.Users don't know the password is blank:
How would a user know to pass
password=""? PDF viewers handle this automatically - agno should too.This fix makes agno match industry-standard behavior by auto-trying blank passwords.
Solution
Automatically try a blank password (
"") when:This matches industry-standard behavior and prevents the zombie document bug.
Changes
Modified
libs/agno/agno/knowledge/reader/pdf_reader.py:_decrypt_pdf()method now attempts blank password before failingBehavior
Testing
Tested with real-world encrypted-but-no-password PDF (
4.BH-Bevel-Helical_Manual-1.pdf):ERROR PDF file "X" is password protected but no password providedINFO Successfully decrypted PDF file "X" with blank password→ vectorization succeedsImpact
Additional Context
This is a common pattern in PDF libraries:
agno should match this industry-standard behavior.
How to Review
_decrypt_pdf()Checklist