Skip to content

Commit

Permalink
add eps test for bad BoundingBox, good ImageData
Browse files Browse the repository at this point in the history
  • Loading branch information
Yay295 committed Feb 6, 2023
1 parent 3d6770d commit be9aea3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion Tests/test_file_eps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:]
Expand Down Expand Up @@ -128,6 +131,17 @@ 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))
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit be9aea3

Please sign in to comment.