mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-12 18:26:17 +03:00
do not crop ImageFont glyphs from negative coordinates
This commit is contained in:
parent
1469e433b6
commit
0eb661b889
|
@ -66,7 +66,9 @@ def test_decompression_bomb():
|
|||
|
||||
@pytest.mark.timeout(4)
|
||||
def test_oom():
|
||||
glyph = struct.pack(">hhhhhhhhhh", 1, 0, 0, 0, 32767, 32767, 0, 0, 32767, 32767)
|
||||
glyph = struct.pack(
|
||||
">hhhhhhhhhh", 1, 0, -32767, -32767, 32767, 32767, -32767, -32767, 32767, 32767
|
||||
)
|
||||
fp = BytesIO(b"PILfont\n\nDATA\n" + glyph * 256)
|
||||
|
||||
font = ImageFont.ImageFont()
|
||||
|
|
|
@ -2652,6 +2652,14 @@ _font_new(PyObject *self_, PyObject *args) {
|
|||
|
||||
// Do not allow glyphs to extend beyond bitmap image
|
||||
// Helps prevent DOS by stopping cropped images being larger than the original
|
||||
if (self->glyphs[i].sx0 < 0) {
|
||||
self->glyphs[i].dx0 -= self->glyphs[i].sx0;
|
||||
self->glyphs[i].sx0 = 0;
|
||||
}
|
||||
if (self->glyphs[i].sy0 < 0) {
|
||||
self->glyphs[i].dy0 -= self->glyphs[i].sy0;
|
||||
self->glyphs[i].sy0 = 0;
|
||||
}
|
||||
if (self->glyphs[i].sx1 > self->bitmap->xsize) {
|
||||
self->glyphs[i].dx1 -= self->glyphs[i].sx1 - self->bitmap->xsize;
|
||||
self->glyphs[i].sx1 = self->bitmap->xsize;
|
||||
|
|
Loading…
Reference in New Issue
Block a user