2023-12-21 14:13:31 +03:00
|
|
|
from __future__ import annotations
|
2024-01-20 14:23:03 +03:00
|
|
|
|
2022-11-03 01:11:57 +03:00
|
|
|
import pytest
|
|
|
|
|
2022-12-31 09:45:09 +03:00
|
|
|
from PIL import Image, ImageDraw, ImageFont
|
|
|
|
|
2022-11-03 01:11:57 +03:00
|
|
|
from .helper import skip_unless_feature
|
|
|
|
|
2022-11-03 01:18:47 +03:00
|
|
|
|
2022-11-03 01:11:57 +03:00
|
|
|
class TestFontCrash:
|
2024-01-22 10:42:43 +03:00
|
|
|
def _fuzz_font(self, font: ImageFont.FreeTypeFont) -> None:
|
2022-11-03 01:11:57 +03:00
|
|
|
# from fuzzers.fuzz_font
|
|
|
|
font.getbbox("ABC")
|
|
|
|
font.getmask("test text")
|
|
|
|
with Image.new(mode="RGBA", size=(200, 200)) as im:
|
|
|
|
draw = ImageDraw.Draw(im)
|
|
|
|
draw.multiline_textbbox((10, 10), "ABC\nAaaa", font, stroke_width=2)
|
|
|
|
draw.text((10, 10), "Test Text", font=font, fill="#000")
|
|
|
|
|
|
|
|
@skip_unless_feature("freetype2")
|
2024-01-22 10:42:43 +03:00
|
|
|
def test_segfault(self) -> None:
|
2022-11-05 07:41:17 +03:00
|
|
|
with pytest.raises(OSError):
|
2022-11-03 01:18:47 +03:00
|
|
|
font = ImageFont.truetype("Tests/fonts/fuzz_font-5203009437302784")
|
2022-11-03 01:11:57 +03:00
|
|
|
self._fuzz_font(font)
|