Skip to content

PdfReadError: File has not been decrypted #1088

Description

@MartinThoma

I was trying to read metadata from a PDF that is not encrypted. The file is encrypted with an empty password:

$ pdfinfo example.pdf

...
Encrypted:      yes (print:yes copy:no change:no addNotes:no algorithm:RC4)
...

Environment

$ python -m platform
Linux-5.4.0-121-generic-x86_64-with-glibc2.31

# Seen first (inclusive)
$ python -c "import PyPDF2;print(PyPDF2.__version__)"
2.4.2

# Seen last (inclusive)
$ python -c "import PyPDF2;print(PyPDF2.__version__)"
2.8.0

Code + PDF

The PDF: pdf/9bc3765eb6426bb34139d419a6e1f79e.pdf

>>> from PyPDF2 import PdfReader
>>> reader = PdfReader("pdf/9bc3765eb6426bb34139d419a6e1f79e.pdf")

>>> len(reader.pages)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/_page.py", line 1469, in __len__
    return self.length_function()
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/_reader.py", line 389, in _get_num_pages
    return self.trailer[TK.ROOT]["/Pages"]["/Count"]  # type: ignore
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 680, in __getitem__
    return dict.__getitem__(self, key).get_object()
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 252, in get_object
    obj = self.pdf.get_object(self)
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/_reader.py", line 1090, in get_object
    raise PdfReadError("File has not been decrypted")
PyPDF2.errors.PdfReadError: File has not been decrypted

>>> reader.metadata
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/_reader.py", line 319, in metadata
    obj = self.trailer[TK.INFO]
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 680, in __getitem__
    return dict.__getitem__(self, key).get_object()
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/generic.py", line 252, in get_object
    obj = self.pdf.get_object(self)
  File "/home/moose/Github/py-pdf/PyPDF2/PyPDF2/_reader.py", line 1090, in get_object
    raise PdfReadError("File has not been decrypted")
PyPDF2.errors.PdfReadError: File has not been decrypted

Metadata

Metadata

Assignees

No one assigned

    Labels

    MCVE in TestsThe MCVE was added to PyPDF2 test suitePdfReaderThe PdfReader component is affectedis-bugFrom a users perspective, this is a bug - a violation of the expected behavior with a compliant PDFworkflow-encryptionFrom a users perspective, encryption is the affected feature/workflow

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions