mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-12-04 00:34:30 +03:00
Close image on ImageFont exception (#9304)
This commit is contained in:
commit
da76f6d99b
|
|
@ -127,11 +127,15 @@ class ImageFont:
|
|||
def _load_pilfont_data(self, file: IO[bytes], image: Image.Image) -> None:
|
||||
# check image
|
||||
if image.mode not in ("1", "L"):
|
||||
image.close()
|
||||
|
||||
msg = "invalid font image mode"
|
||||
raise TypeError(msg)
|
||||
|
||||
# read PILfont header
|
||||
if file.read(8) != b"PILfont\n":
|
||||
image.close()
|
||||
|
||||
msg = "Not a PILfont file"
|
||||
raise SyntaxError(msg)
|
||||
file.readline()
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user