Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handling of incomplete EOF markers #2853

Closed
stefan6419846 opened this issue Sep 16, 2024 · 1 comment · Fixed by #2855
Closed

Handling of incomplete EOF markers #2853

stefan6419846 opened this issue Sep 16, 2024 · 1 comment · Fixed by #2855
Labels
is-robustness-issue From a users perspective, this is about robustness PdfReader The PdfReader component is affected

Comments

@stefan6419846
Copy link
Collaborator

I just stumbled upon a PDF sent by e-mail where the final OF of the EOF marker has been missing. Apparently, pdf.js and Evince are able to display it correctly, while pypdf fails.

Environment

Which environment were you using when you encountered the problem?

$ python -m platform
Linux-5.14.21-150400.24.100-default-x86_64-with-glibc2.31

$ python -c "import pypdf;print(pypdf._debug_versions)"
pypdf==4.3.1, crypt_provider=('pycryptodome', '3.18.0'), PIL=10.0.0

Note: The version is the latest main code.

Code + PDF

This is a minimal, complete example that shows the issue:

from pypdf import PdfReader

reader = PdfReader('file.pdf')

For the file, just take any valid PDF file and remove the final OF characters of %%EOF.

Traceback

This is the complete traceback I see:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/stefan/temp/pdf/pypdf/_reader.py", line 142, in __init__
    self.read(stream)
  File "/home/stefan/temp/pdf/pypdf/_reader.py", line 566, in read
    self._find_eof_marker(stream)
  File "/home/stefan/temp/pdf/pypdf/_reader.py", line 658, in _find_eof_marker
    line = read_previous_line(stream)
  File "/home/stefan/temp/pdf/pypdf/_utils.py", line 279, in read_previous_line
    raise PdfStreamError(STREAM_TRUNCATED_PREMATURELY)
pypdf.errors.PdfStreamError: Stream has ended unexpectedly

@stefan6419846 stefan6419846 added PdfReader The PdfReader component is affected is-robustness-issue From a users perspective, this is about robustness labels Sep 16, 2024
@pubpub-zz
Copy link
Collaborator

there is one extra point behind that I've detected : If the %%EOF is truncated/missing, pypdf searches further in the file. If the file is linearized or has been incrementally built, a full "section" may be ignored without warning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
is-robustness-issue From a users perspective, this is about robustness PdfReader The PdfReader component is affected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants