Skip to content

Commit

Permalink
Merge pull request #8144 from Yay295/eps_plugin_return_break
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jun 25, 2024
2 parents d2b5e11 + 065aeae commit 1661343
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/PIL/EpsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,11 @@ def _open(self) -> None:
trailer_reached = False

def check_required_header_comments() -> None:
"""
The EPS specification requires that some headers exist.
This should be checked when the header comments formally end,
when image data starts, or when the file ends, whichever comes first.
"""
if "PS-Adobe" not in self.info:
msg = 'EPS header missing "%!PS-Adobe" comment'
raise SyntaxError(msg)
Expand Down Expand Up @@ -270,6 +275,8 @@ def _read_comment(s: str) -> bool:
if byte == b"":
# if we didn't read a byte we must be at the end of the file
if bytes_read == 0:
if reading_header_comments:
check_required_header_comments()
break
elif byte in b"\r\n":
# if we read a line ending character, ignore it and parse what
Expand Down Expand Up @@ -365,8 +372,6 @@ def _read_comment(s: str) -> bool:
trailer_reached = True
bytes_read = 0

check_required_header_comments()

if not self._size:
msg = "cannot determine EPS bounding box"
raise OSError(msg)
Expand Down

0 comments on commit 1661343

Please sign in to comment.