Prevent infinite loop in readObject() function. Patch by dhudson1. Closes mstamy2/PyPDF2#184

This commit is contained in:
Henri Salo 2015-08-18 13:42:22 +03:00
parent 7456f0acea
commit 48193975e5
1 changed files with 4 additions and 0 deletions

View File

@ -82,6 +82,10 @@ def readObject(stream, pdf):
# comment
while tok not in (b_('\r'), b_('\n')):
tok = stream.read(1)
# Prevents an infinite loop by raising an error if the stream is at
# the EOF
if len(tok) <= 0:
raise PdfStreamError("File ended unexpectedly.")
tok = readNonWhitespace(stream)
stream.seek(-1, 1)
return readObject(stream, pdf)