diff --git a/Tests/images/zero_bb_eof_before_boundingbox.eps b/Tests/images/zero_bb_eof_before_boundingbox.eps new file mode 100644 index 000000000..c268bffd1 Binary files /dev/null and b/Tests/images/zero_bb_eof_before_boundingbox.eps differ diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 21c1fd778..4f4d26fb1 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -406,10 +406,16 @@ def test_timeout(test_file): pass -def test_boundary_box_in_trailer(): - # Check whether boundary boxes are parsed in the same way - # when specified in the header or the trailer +def test_bounding_box_in_trailer(): + # Check bounding boxes are parsed in the same way + # when specified in the header and the trailer with Image.open("Tests/images/zero_bb_trailer.eps") as trailer_image, Image.open( FILE1 ) as header_image: assert trailer_image.size == header_image.size + + +def test_eof_before_bounding_box(): + with pytest.raises(OSError): + with Image.open("Tests/images/zero_bb_eof_before_boundingbox.eps"): + pass diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index e67519be1..3a71b35cf 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -367,10 +367,9 @@ class EpsImageFile(ImageFile.ImageFile): # Load EPS trailer # if this line starts with "%%EOF", - # then we've reached the end of the trailer + # then we've reached the end of the file if bytes_mv[:5] == b"%%EOF": - reading_trailer_comments = False - continue + break s = str(bytes_mv[:bytes_read], "latin-1") _read_comment(s)