Skip to content

Commit bf014af

Browse files
committed
check required EPS header comments at end of file, not always
1 parent 9e46423 commit bf014af

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/PIL/EpsImagePlugin.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ def _open(self) -> None:
230230
trailer_reached = False
231231

232232
def check_required_header_comments() -> None:
233+
"""
234+
The EPS spec requires that some headers exist.
235+
This should be checked after all headers have been read,
236+
or at the end of the file if that comes first.
237+
"""
233238
if "PS-Adobe" not in self.info:
234239
msg = 'EPS header missing "%!PS-Adobe" comment'
235240
raise SyntaxError(msg)
@@ -270,6 +275,8 @@ def _read_comment(s: str) -> bool:
270275
if byte == b"":
271276
# if we didn't read a byte we must be at the end of the file
272277
if bytes_read == 0:
278+
if reading_header_comments:
279+
check_required_header_comments()
273280
break
274281
elif byte in b"\r\n":
275282
# if we read a line ending character, ignore it and parse what
@@ -365,8 +372,6 @@ def _read_comment(s: str) -> bool:
365372
trailer_reached = True
366373
bytes_read = 0
367374

368-
check_required_header_comments()
369-
370375
if not self._size:
371376
msg = "cannot determine EPS bounding box"
372377
raise OSError(msg)

0 commit comments

Comments
 (0)