Skip to content

Commit 42c7678

Browse files
radarhereYay295
authored andcommitted
Break if the bit depth or mode id are unknown
1 parent 081f37f commit 42c7678

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

src/PIL/EpsImagePlugin.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -320,21 +320,26 @@ def read_comment(s: str) -> bool:
320320
# binary/ascii (1: binary, 2: ascii)
321321
# data start identifier (the image data follows after a single line
322322
# consisting only of this quoted value)
323+
if imagedata_size:
324+
bytes_read = 0
325+
continue
326+
323327
image_data_values = byte_arr[11:bytes_read].split(None, 7)
324328
columns, rows, bit_depth, mode_id = (
325329
int(value) for value in image_data_values[:4]
326330
)
327331

328-
if not imagedata_size:
329-
imagedata_size = columns, rows
332+
if bit_depth == 1:
333+
self._mode = "1"
334+
elif bit_depth == 8:
335+
try:
336+
self._mode = self.mode_map[mode_id]
337+
except ValueError:
338+
break
339+
else:
340+
break
330341

331-
if bit_depth == 1:
332-
self._mode = "1"
333-
elif bit_depth == 8:
334-
try:
335-
self._mode = self.mode_map[mode_id]
336-
except ValueError:
337-
pass
342+
imagedata_size = columns, rows
338343
elif bytes_mv[:5] == b"%%EOF":
339344
break
340345
elif trailer_reached and reading_trailer_comments:

0 commit comments

Comments
 (0)