Skip to content

Commit 485d988

Browse files
committed
Limit length of read operation
1 parent 57a5f76 commit 485d988

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

Tests/test_imagefont.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,11 @@ def test_stroke_mask() -> None:
492492
assert mask.getpixel((42, 5)) == 255
493493

494494

495+
def test_load_invalid_file() -> None:
496+
with pytest.raises(SyntaxError, match="Not a PILfont file"):
497+
ImageFont.load("Tests/images/1_trns.png")
498+
499+
495500
def test_load_when_image_not_found() -> None:
496501
with tempfile.NamedTemporaryFile(delete=False) as tmp:
497502
pass

src/PIL/ImageFont.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def _load_pilfont(self, filename: str) -> None:
126126

127127
def _load_pilfont_data(self, file: IO[bytes], image: Image.Image) -> None:
128128
# read PILfont header
129-
if file.readline() != b"PILfont\n":
129+
if file.read(8) != b"PILfont\n":
130130
msg = "Not a PILfont file"
131131
raise SyntaxError(msg)
132132
file.readline()

0 commit comments

Comments
 (0)