Skip to content

Commit

Permalink
Fix a bug which could result in a "Stream has ended unexpectedly" err…
Browse files Browse the repository at this point in the history
…or being raised unecessarily if a Name object runs right up against the end of a file stream.
  • Loading branch information
speedplane committed Jun 30, 2015
1 parent ee0ace6 commit 431ba70
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions PyPDF2/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ def writeToStream(self, stream, encryption_key):


class NameObject(str, PdfObject):
delimiterPattern = re.compile(b_("\s+|[()<>[\]{}/%]"))
delimiterPattern = re.compile(b_(r"\s+|[()<>[\]{}/%]"))
surfix = b_("/")

def writeToStream(self, stream, encryption_key):
Expand All @@ -473,7 +473,8 @@ def readFromStream(stream, pdf):
name = stream.read(1)
if name != NameObject.surfix:
raise utils.PdfReadError("name read error")
name += utils.readUntilRegex(stream, NameObject.delimiterPattern)
name += utils.readUntilRegex(stream, NameObject.delimiterPattern,
ignore_eof=True)
if debug: print(name)
try:
return NameObject(name.decode('utf-8'))
Expand Down

0 comments on commit 431ba70

Please sign in to comment.