From e70c04642101f58c8506431972d83614a8e3faea Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 21 Mar 2026 10:10:07 +1100 Subject: [PATCH] Catch OSError for FreeType >= 2.14.0 --- Tests/test_font_crash.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Tests/test_font_crash.py b/Tests/test_font_crash.py index c3e62abf62e..db9dcc58f10 100644 --- a/Tests/test_font_crash.py +++ b/Tests/test_font_crash.py @@ -1,8 +1,10 @@ from __future__ import annotations +import pytest + from PIL import Image, ImageDraw, ImageFont -from .helper import skip_unless_feature_version +from .helper import has_feature_version, skip_unless_feature_version class TestFontCrash: @@ -18,5 +20,10 @@ def _fuzz_font(self, font: ImageFont.FreeTypeFont) -> None: @skip_unless_feature_version("freetype2", "2.12.0") def test_segfault(self) -> None: - font = ImageFont.truetype("Tests/fonts/fuzz_font-5203009437302784") - self._fuzz_font(font) + font_path = "Tests/fonts/fuzz_font-5203009437302784" + if has_feature_version("freetype2", "2.14.0"): + with pytest.raises(OSError, match="broken file"): + ImageFont.truetype(font_path) + else: + font = ImageFont.truetype(font_path) + self._fuzz_font(font)