diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index 26ac2e5a191..5c0c3721b08 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -56,7 +56,10 @@ simple_eps_file_without_version = simple_eps_file[1:] simple_eps_file_without_boundingbox = simple_eps_file[:1] + simple_eps_file[2:] simple_eps_file_with_invalid_boundingbox = ( - simple_eps_file[:1] + (b"%%BoundingBox",) + simple_eps_file[2:] + simple_eps_file[:1] + (b"%%BoundingBox: a b c d",) + simple_eps_file[2:] +) +simple_eps_file_with_invalid_boundingbox_valid_imagedata = ( + simple_eps_file_with_invalid_boundingbox + (b"%ImageData: 100 100 8 3",) ) simple_eps_file_with_long_ascii_comment = ( simple_eps_file[:2] + (b"%%Comment: " + b"X" * 300,) + simple_eps_file[2:] @@ -128,6 +131,15 @@ def test_invalid_boundingbox_comment(prefix): EpsImagePlugin.EpsImageFile(data) +@pytest.mark.parametrize("prefix", (b"", simple_binary_header)) +def test_invalid_boundingbox_comment_valid_imagedata_comment(prefix): + data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_invalid_boundingbox_valid_imagedata)) + with Image.open(data) as img: + assert img.mode == "RGB" + assert img.size == (100, 100) + assert img.format == "EPS" + + @pytest.mark.parametrize("prefix", (b"", simple_binary_header)) def test_ascii_comment_too_long(prefix): data = io.BytesIO(prefix + b"\n".join(simple_eps_file_with_long_ascii_comment)) diff --git a/src/PIL/EpsImagePlugin.py b/src/PIL/EpsImagePlugin.py index 4c0ab0e127b..2a4e804ce21 100644 --- a/src/PIL/EpsImagePlugin.py +++ b/src/PIL/EpsImagePlugin.py @@ -314,7 +314,7 @@ def check_required_header_comments(): # Check for an "ImageData" descriptor # Encoded bitmapped image. - x, y, bi, mo = byte_arr[11:].split(None, 7)[:4] + x, y, bi, mo = byte_arr[11:bytes_read].split(None, 7)[:4] if int(bi) == 1: self.mode = "1"