Allow for an empty line in EPS header data

This commit is contained in:
Andrew Murray 2017-12-22 17:01:54 +11:00
parent 3d8035bf31
commit e107ed6fcf
3 changed files with 52 additions and 39 deletions

View File

@ -227,9 +227,11 @@ class EpsImageFile(ImageFile.ImageFile):
# #
# Load EPS header # Load EPS header
s = fp.readline().strip('\r\n') s_raw = fp.readline()
s = s_raw.strip('\r\n')
while s: while s_raw:
if s:
if len(s) > 255: if len(s) > 255:
raise SyntaxError("not an EPS file") raise SyntaxError("not an EPS file")
@ -271,9 +273,10 @@ class EpsImageFile(ImageFile.ImageFile):
else: else:
raise IOError("bad EPS header") 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 break
# #

Binary file not shown.

View File

@ -278,6 +278,16 @@ class TestFileEps(PillowTestCase):
# Assert # Assert
self.assertEqual(img.mode, "RGB") self.assertEqual(img.mode, "RGB")
def test_emptyline(self):
# Test file includes an empty line in the header data
emptyline_file = "Tests/images/zero_bb_emptyline.eps"
image = Image.open(emptyline_file)
image.load()
self.assertEqual(image.mode, "RGB")
self.assertEqual(image.size, (460, 352))
self.assertEqual(image.format, "EPS")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()