Skip to content

Commit 5721577

Browse files
committed
Stop reading EPS at EOF marker
1 parent b3a7ae0 commit 5721577

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

Tests/test_file_eps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,11 @@ def test_eof_before_bounding_box():
436436
with pytest.raises(OSError):
437437
with Image.open("Tests/images/zero_bb_eof_before_boundingbox.eps"):
438438
pass
439+
440+
441+
def test_invalid_data_after_eof() -> None:
442+
with open("Tests/images/illuCS6_preview.eps", "rb") as f:
443+
img_bytes = io.BytesIO(f.read() + b"\r\n%" + (b" " * 255))
444+
445+
with Image.open(img_bytes) as img:
446+
assert img.mode == "RGB"

src/PIL/EpsImagePlugin.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -356,14 +356,10 @@ def _read_comment(s):
356356

357357
self._size = columns, rows
358358
return
359+
elif bytes_mv[:5] == b"%%EOF":
360+
break
359361
elif trailer_reached and reading_trailer_comments:
360362
# Load EPS trailer
361-
362-
# if this line starts with "%%EOF",
363-
# then we've reached the end of the file
364-
if bytes_mv[:5] == b"%%EOF":
365-
break
366-
367363
s = str(bytes_mv[:bytes_read], "latin-1")
368364
_read_comment(s)
369365
elif bytes_mv[:9] == b"%%Trailer":

0 commit comments

Comments
 (0)