Skip to content

Commit db1e458

Browse files
authored
BUG: Use 1MB as offset for readNextEndLine (#321)
Try to find “%%EOF” in last 1Mb of file. This fixes the issue with reading Selenium-generated PDF files. Closes #177 Closes #442 Closes #480
1 parent b36a564 commit db1e458

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

PyPDF2/pdf.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,12 +1820,12 @@ def read(self, stream):
18201820
stream.seek(-1, 2)
18211821
if not stream.tell():
18221822
raise PdfReadError('Cannot read an empty file')
1823-
last1K = stream.tell() - 1024 + 1 # offset of last 1024 bytes of stream
1823+
last1M = stream.tell() - 1024 * 1024 + 1 # offset of last MB of stream
18241824
line = b_('')
18251825
while line[:5] != b_("%%EOF"):
1826-
if stream.tell() < last1K:
1826+
if stream.tell() < last1M:
18271827
raise PdfReadError("EOF marker not found")
1828-
line = self.readNextEndLine(stream, last1K)
1828+
line = self.readNextEndLine(stream)
18291829
if debug: print(" line:",line)
18301830

18311831
# find startxref entry - the location of the xref table

0 commit comments

Comments
 (0)