diff --git a/Tests/fonts/oom-e8e927ba6c0d38274a37c1567560eb33baf74627.ttf b/Tests/fonts/oom-e8e927ba6c0d38274a37c1567560eb33baf74627.ttf new file mode 100644 index 00000000000..79013251524 Binary files /dev/null and b/Tests/fonts/oom-e8e927ba6c0d38274a37c1567560eb33baf74627.ttf differ diff --git a/Tests/test_imagefont.py b/Tests/test_imagefont.py index dc88cb31d27..883c1417096 100644 --- a/Tests/test_imagefont.py +++ b/Tests/test_imagefont.py @@ -997,3 +997,16 @@ def fake_version_module(module): # Act / Assert with pytest.warns(DeprecationWarning): ImageFont.truetype(FONT_PATH, FONT_SIZE) + + +@pytest.mark.parametrize( + "test_file", + [ + "Tests/fonts/oom-e8e927ba6c0d38274a37c1567560eb33baf74627.ttf", + ], +) +def test_oom(test_file): + with open(test_file, "rb") as f: + font = ImageFont.truetype(BytesIO(f.read())) + with pytest.raises(Image.DecompressionBombError): + font.getmask("Test Text") diff --git a/src/PIL/ImageFont.py b/src/PIL/ImageFont.py index c48d8983565..2f63ddae6fc 100644 --- a/src/PIL/ImageFont.py +++ b/src/PIL/ImageFont.py @@ -669,6 +669,7 @@ def getmask2( ) size = size[0] + stroke_width * 2, size[1] + stroke_width * 2 offset = offset[0] - stroke_width, offset[1] - stroke_width + Image._decompression_bomb_check(size) im = fill("RGBA" if mode == "RGBA" else "L", size, 0) self.font.render( text, im.id, mode, direction, features, language, stroke_width, ink