1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
|
From 48193975e5a0e48ebbb68217f8533ad2bfbdede2 Mon Sep 17 00:00:00 2001
From: Henri Salo <henri.salo@nixu.com>
Date: Tue, 18 Aug 2015 13:42:22 +0300
Subject: [PATCH] Prevent infinite loop in readObject() function. Patch by
dhudson1. Closes mstamy2/PyPDF2#184
---
PyPDF2/generic.py | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/PyPDF2/generic.py b/PyPDF2/generic.py
index df1e028..657612a 100644
--- a/PyPDF2/generic.py
+++ b/PyPDF2/generic.py
@@ -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)
|