Skip to content

Commit ba65f0b

Browse files
wiredfoolhugovk
authored andcommitted
Fix Memory DOS in ImageFont
* A corrupt or specially crafted TTF font could have font metrics that lead to unreasonably large sizes when rendering text in font. ImageFont.py did not check the image size before allocating memory for it. * Found with oss-fuzz * This dates from the PIL fork
1 parent bb6c11f commit ba65f0b

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed
Binary file not shown.

Tests/test_imagefont.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -997,3 +997,16 @@ def fake_version_module(module):
997997
# Act / Assert
998998
with pytest.warns(DeprecationWarning):
999999
ImageFont.truetype(FONT_PATH, FONT_SIZE)
1000+
1001+
1002+
@pytest.mark.parametrize(
1003+
"test_file",
1004+
[
1005+
"Tests/fonts/oom-e8e927ba6c0d38274a37c1567560eb33baf74627.ttf",
1006+
],
1007+
)
1008+
def test_oom(test_file):
1009+
with open(test_file, "rb") as f:
1010+
font = ImageFont.truetype(BytesIO(f.read()))
1011+
with pytest.raises(Image.DecompressionBombError):
1012+
font.getmask("Test Text")

src/PIL/ImageFont.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -669,6 +669,7 @@ def getmask2(
669669
)
670670
size = size[0] + stroke_width * 2, size[1] + stroke_width * 2
671671
offset = offset[0] - stroke_width, offset[1] - stroke_width
672+
Image._decompression_bomb_check(size)
672673
im = fill("RGBA" if mode == "RGBA" else "L", size, 0)
673674
self.font.render(
674675
text, im.id, mode, direction, features, language, stroke_width, ink

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy