Do not return negative width for text
This commit is contained in:
parent
24696af889
commit
e97c8323e8
@ -68,6 +68,15 @@ def test_textbbox(font: ImageFont.ImageFont) -> None:
|
||||
assert d.textbbox((0, 0), "test", font=font) == (0, 0, 24, 11)
|
||||
|
||||
|
||||
def test_negative_dx() -> None:
|
||||
glyph = struct.pack(">hhhhhhhhhh", -1, 0, 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
fp = BytesIO(b"PILfont\n\nDATA\n" + glyph * 256)
|
||||
|
||||
font = ImageFont.ImageFont()
|
||||
font._load_pilfont_data(fp, Image.new("L", (1, 1)))
|
||||
assert font.getlength("A") == 0
|
||||
|
||||
|
||||
def test_decompression_bomb() -> None:
|
||||
glyph = struct.pack(">hhhhhhhhhh", 1, 0, 0, 0, 256, 256, 0, 0, 256, 256)
|
||||
fp = BytesIO(b"PILfont\n\nDATA\n" + glyph * 256)
|
||||
|
||||
@ -2779,6 +2779,9 @@ textwidth(ImagingFontObject *self, const unsigned char *text) {
|
||||
xsize += self->glyphs[*text].dx;
|
||||
}
|
||||
|
||||
if (xsize < 0) {
|
||||
return 0;
|
||||
}
|
||||
return xsize;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user