Skip to content

Commit

Permalink
Ignores multiple definitions only when strict = False, prevent except…
Browse files Browse the repository at this point in the history
…ion when attempting to correct non-zeroed xrefs
  • Loading branch information
mstamy2 committed Feb 25, 2014
1 parent 9f27ebf commit 7f572ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
10 changes: 8 additions & 2 deletions PyPDF2/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,6 @@ def writeToStream(self, stream, encryption_key):
stream.write(b_(">>"))

def readFromStream(stream, pdf):
# This method is broken in Python 3+ and needs work,
# especially when finding endstream marker
debug = False
tmp = stream.read(2)
if tmp != b_("<<"):
Expand All @@ -589,6 +587,14 @@ def readFromStream(stream, pdf):
value = readObject(stream, pdf)
if not data.get(key):
data[key] = value
elif pdf.strict:
# multiple definitions of key not permitted
raise utils.PdfReadError("Multiple definitions in dictionary at byte %s for key %s" \
% (utils.hexStr(stream.tell()), key))
else:
warnings.warn("Multiple definitions in dictionary at byte %s for key %s" \
% (utils.hexStr(stream.tell()), key), utils.PdfReadWarning)

pos = stream.tell()
s = readNonWhitespace(stream)
if s == b_('s') and stream.read(5) == b_('tream'):
Expand Down
5 changes: 4 additions & 1 deletion PyPDF2/pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -1433,7 +1433,10 @@ def used_before(num, generation):
if gen == 65535: continue
for id in self.xref[gen]:
stream.seek(self.xref[gen][id], 0)
pid, pgen = self.readObjectHeader(stream)
try:
pid, pgen = self.readObjectHeader(stream)
except ValueError:
break
if pid == id - self.xrefIndex:
self._zeroXref(gen)
break
Expand Down

0 comments on commit 7f572ca

Please sign in to comment.