check required EPS header comments at end of file, not always

This commit is contained in:
Yay295 2024-06-17 01:23:36 -05:00
parent 1c8d270746
commit a2c0a90c44

View File

@ -230,6 +230,11 @@ class EpsImageFile(ImageFile.ImageFile):
trailer_reached = False trailer_reached = False
def check_required_header_comments() -> None: def check_required_header_comments() -> None:
"""
The EPS spec requires that some headers exist.
This should be checked after all headers have been read,
or at the end of the file if that comes first.
"""
if "PS-Adobe" not in self.info: if "PS-Adobe" not in self.info:
msg = 'EPS header missing "%!PS-Adobe" comment' msg = 'EPS header missing "%!PS-Adobe" comment'
raise SyntaxError(msg) raise SyntaxError(msg)
@ -270,6 +275,8 @@ class EpsImageFile(ImageFile.ImageFile):
if byte == b"": if byte == b"":
# if we didn't read a byte we must be at the end of the file # if we didn't read a byte we must be at the end of the file
if bytes_read == 0: if bytes_read == 0:
if reading_header_comments:
check_required_header_comments()
break break
elif byte in b"\r\n": elif byte in b"\r\n":
# if we read a line ending character, ignore it and parse what # if we read a line ending character, ignore it and parse what
@ -365,8 +372,6 @@ class EpsImageFile(ImageFile.ImageFile):
trailer_reached = True trailer_reached = True
bytes_read = 0 bytes_read = 0
check_required_header_comments()
if not self._size: if not self._size:
msg = "cannot determine EPS bounding box" msg = "cannot determine EPS bounding box"
raise OSError(msg) raise OSError(msg)