Skip to content

Commit

Permalink
Merge pull request #136 from maxpmaxp/issue-135-linearized-pdf-traile…
Browse files Browse the repository at this point in the history
…r-parsing-issue

ISSUE-135: linearized PDF trailer parsing issue
  • Loading branch information
maxpmaxp authored Sep 5, 2024
2 parents 5757c83 + 8f4b103 commit 2cfb66e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
pdfreader 0.1.16dev
---------------------------
- issue #135 - trailer parsing issue for linearized PDFs

pdfreader 0.1.15
---------------------------
- don't raise error on unsupported stream filters, return raw unfiltered data instead
Expand Down
22 changes: 14 additions & 8 deletions pdfreader/parsers/document.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re

from ..constants import WHITESPACE_CODES, EOL, SP
Expand Down Expand Up @@ -558,14 +559,19 @@ def locate_backwards_from_trailer(self, num, gen):
chunk_len = len(expected_obj)
obj_header = self.read(chunk_len)

while obj_header != expected_obj:
self.skip_backwards_until(b"endobj")
self.skip_backwards_until(b"endobj")
self.read(6)
self.maybe_spaces_or_comments()
obj_header = self.read(chunk_len)
if len(obj_header) < chunk_len:
return
try:
while obj_header != expected_obj:
self.skip_backwards_until(b"endobj")
self.skip_backwards_until(b"endobj")
self.read(6)
self.maybe_spaces_or_comments()
obj_header = self.read(chunk_len)
if len(obj_header) < chunk_len:
return
except TypeError:
# Issue 135: https://github.com/maxpmaxp/pdfreader/issues/135
logging.debug("Failed to locate backwards from trailer")
return

self.read_backward(chunk_len)
obj = self.indirect_object()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
if sys.version_info[:2] < (3, 6):
warnings.warn("Python version >= 3.6 required.")

version = '0.1.15'
version = '0.1.16dev'


import os.path
Expand Down

0 comments on commit 2cfb66e

Please sign in to comment.