Skip to content

Commit 797d83f

Browse files
authored
Seek past BeginBinary data when parsing EPS metadata (#9211)
2 parents cec262c + 222933d commit 797d83f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

Tests/test_file_eps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,14 @@ def test_load_long_binary_data(prefix: bytes) -> None:
197197
assert img.format == "EPS"
198198

199199

200+
def test_begin_binary() -> None:
201+
with open("Tests/images/eps/binary_preview_map.eps", "rb") as fp:
202+
data = bytearray(fp.read())
203+
data[76875 : 76875 + 11] = b"%" * 11
204+
with Image.open(io.BytesIO(data)) as img:
205+
assert img.size == (399, 480)
206+
207+
200208
@mark_if_feature_version(
201209
pytest.mark.valgrind_known_error, "libjpeg_turbo", "2.0", reason="Known Failing"
202210
)

src/PIL/EpsImagePlugin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,9 @@ def read_comment(s: str) -> bool:
354354
read_comment(s)
355355
elif bytes_mv[:9] == b"%%Trailer":
356356
trailer_reached = True
357+
elif bytes_mv[:14] == b"%%BeginBinary:":
358+
bytecount = int(byte_arr[14:bytes_read])
359+
self.fp.seek(bytecount, os.SEEK_CUR)
357360
bytes_read = 0
358361

359362
# A "BoundingBox" is always required,

0 commit comments

Comments
 (0)