Skip to content

Commit

Permalink
Allow for an empty line in EPS header data
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 22, 2017
1 parent 9fcc58d commit 8bfa2e8
Show file tree
Hide file tree
Showing 3 changed files with 1,545 additions and 39 deletions.
81 changes: 42 additions & 39 deletions PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,53 +227,56 @@ def _open(self):
#
# Load EPS header

s = fp.readline().strip('\r\n')
s_raw = fp.readline()
s = s_raw.strip('\r\n')

while s:
if len(s) > 255:
raise SyntaxError("not an EPS file")

try:
m = split.match(s)
except re.error as v:
raise SyntaxError("not an EPS file")
while s_raw:
if s:
if len(s) > 255:
raise SyntaxError("not an EPS file")

if m:
k, v = m.group(1, 2)
self.info[k] = v
if k == "BoundingBox":
try:
# Note: The DSC spec says that BoundingBox
# fields should be integers, but some drivers
# put floating point values there anyway.
box = [int(float(i)) for i in v.split()]
self.size = box[2] - box[0], box[3] - box[1]
self.tile = [("eps", (0, 0) + self.size, offset,
(length, box))]
except:
pass
try:
m = split.match(s)
except re.error as v:
raise SyntaxError("not an EPS file")

else:
m = field.match(s)
if m:
k = m.group(1)
k, v = m.group(1, 2)
self.info[k] = v
if k == "BoundingBox":
try:
# Note: The DSC spec says that BoundingBox
# fields should be integers, but some drivers
# put floating point values there anyway.
box = [int(float(i)) for i in v.split()]
self.size = box[2] - box[0], box[3] - box[1]
self.tile = [("eps", (0, 0) + self.size, offset,
(length, box))]
except:
pass

if k == "EndComments":
break
if k[:8] == "PS-Adobe":
self.info[k[:8]] = k[9:]
else:
self.info[k] = ""
elif s[0] == '%':
# handle non-DSC Postscript comments that some
# tools mistakenly put in the Comments section
pass
else:
raise IOError("bad EPS header")
m = field.match(s)
if m:
k = m.group(1)

if k == "EndComments":
break
if k[:8] == "PS-Adobe":
self.info[k[:8]] = k[9:]
else:
self.info[k] = ""
elif s[0] == '%':
# handle non-DSC Postscript comments that some
# tools mistakenly put in the Comments section
pass
else:
raise IOError("bad EPS header")

s = fp.readline().strip('\r\n')
s_raw = fp.readline()
s = s_raw.strip('\r\n')

if s[:1] != "%":
if s and s[:1] != "%":
break

#
Expand Down
Loading

0 comments on commit 8bfa2e8

Please sign in to comment.