From 0f788b3a425e96e19975c356ec56762d87203084 Mon Sep 17 00:00:00 2001 From: Aarni Koskela Date: Tue, 28 Nov 2023 12:56:32 +0200 Subject: [PATCH] Improve error message when creating TrueType fonts of negative size Fixes #7583 --- src/PIL/ImageFont.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index c2956213519..1324f8b4e6f 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -790,6 +790,10 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None): :exception OSError: If the file could not be read. """ + if size <= 0: + msg = "font size must be positive" + raise ValueError(msg) + def freetype(font): return FreeTypeFont(font, size, index, encoding, layout_engine)