Skip to content

Commit

Permalink
Do not try and crop glyphs from outside of source ImageFont image
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 30, 2023
1 parent c9805df commit 0870923
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/releasenotes/10.2.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ Restricted environment keys for ImageMath.eval
arbitrary code. To prevent this, keys matching the names of builtins and keys
containing double underscores will now raise a :py:exc:`ValueError`.

Trim glyph size in ImageFont.getmask
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

:py:class:`PIL.ImageFont.ImageFont` now trims the size of individual glyphs so that
they do not extend beyond the bitmap image.

A decompression bomb check has been also been added to
:py:meth:`PIL.ImageFont.ImageFont.getmask`.

Other Changes
=============

Expand Down
8 changes: 8 additions & 0 deletions src/_imaging.c
Original file line number Diff line number Diff line change
Expand Up @@ -2649,6 +2649,14 @@ _font_new(PyObject *self_, PyObject *args) {
self->glyphs[i].sy0 = S16(B16(glyphdata, 14));
self->glyphs[i].sx1 = S16(B16(glyphdata, 16));
self->glyphs[i].sy1 = S16(B16(glyphdata, 18));
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;
}
if (self->glyphs[i].sy1 > self->bitmap->ysize) {
self->glyphs[i].dy1 -= self->glyphs[i].sy1 - self->bitmap->ysize;
self->glyphs[i].sy1 = self->bitmap->ysize;
}
if (self->glyphs[i].dy0 < y0) {
y0 = self->glyphs[i].dy0;
}
Expand Down

0 comments on commit 0870923

Please sign in to comment.