Skip to content

Commit

Permalink
Exception handling for illegal characters in Name Objects
Browse files Browse the repository at this point in the history
  • Loading branch information
mstamy2 committed Jan 23, 2014
1 parent b0354f6 commit 7cfddb5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions PyPDF2/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def readObject(stream, pdf):
return readStringFromStream(stream)
elif tok == b_('/'):
# name object
return NameObject.readFromStream(stream)
return NameObject.readFromStream(stream, pdf)
elif tok == b_('['):
# array object
return ArrayObject.readFromStream(stream, pdf)
Expand Down Expand Up @@ -452,7 +452,7 @@ def __init__(self, data):
def writeToStream(self, stream, encryption_key):
stream.write(b_(self))

def readFromStream(stream):
def readFromStream(stream, pdf):
debug = False
if debug: print((stream.tell()))
name = stream.read(1)
Expand All @@ -471,8 +471,13 @@ def readFromStream(stream):
try:
return NameObject(name.decode('utf-8'))
except UnicodeDecodeError as e:
print("error decoding string", e)
return NameObject(name)
# Name objects should represent irregular characters
# with a '#' followed by the symbol's hex number
if not pdf.strict:
warnings.warn("Illegal character in Name Object", utils.PdfReadWarning)
return NameObject(name)
else:
raise utils.PdfReadError("Illegal character in Name Object")

readFromStream = staticmethod(readFromStream)

Expand Down

0 comments on commit 7cfddb5

Please sign in to comment.