Skip to content

Commit

Permalink
Merge pull request #7218 from radarhere/null
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jun 18, 2023
2 parents 934a6c6 + eaf5c09 commit d64739f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
Binary file not shown.
1 change: 1 addition & 0 deletions Tests/test_imagefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -1042,6 +1042,7 @@ def test_render_mono_size():
"test_file",
[
"Tests/fonts/oom-e8e927ba6c0d38274a37c1567560eb33baf74627.ttf",
"Tests/fonts/oom-4da0210eb7081b0bf15bf16cc4c52ce02c1e1bbc.ttf",
],
)
def test_oom(test_file):
Expand Down
24 changes: 19 additions & 5 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,13 +880,17 @@ font_render(FontObject *self, PyObject *args) {
width += stroke_width * 2 + ceil(x_start);
height += stroke_width * 2 + ceil(y_start);
if (max_image_pixels != Py_None) {
if (width * height > PyLong_AsLong(max_image_pixels) * 2) {
if ((long long)width * height > PyLong_AsLongLong(max_image_pixels) * 2) {
PyMem_Del(glyph_info);
return Py_BuildValue("O(ii)(ii)", Py_None, width, height, 0, 0);
}
}

image = PyObject_CallFunction(fill, "s(ii)", strcmp(mode, "RGBA") == 0 ? "RGBA" : "L", width, height);
if (image == NULL) {
PyMem_Del(glyph_info);
return NULL;
}
id = PyLong_AsSsize_t(PyObject_GetAttrString(image, "id"));
im = (Imaging)id;

Expand All @@ -900,7 +904,8 @@ font_render(FontObject *self, PyObject *args) {
if (stroke_width) {
error = FT_Stroker_New(library, &stroker);
if (error) {
return geterror(error);
geterror(error);
goto glyph_error;
}

FT_Stroker_Set(
Expand All @@ -923,7 +928,8 @@ font_render(FontObject *self, PyObject *args) {
error =
FT_Load_Glyph(self->face, glyph_info[i].index, load_flags | FT_LOAD_RENDER);
if (error) {
return geterror(error);
geterror(error);
goto glyph_error;
}

glyph_slot = self->face->glyph;
Expand Down Expand Up @@ -954,7 +960,8 @@ font_render(FontObject *self, PyObject *args) {

error = FT_Load_Glyph(self->face, glyph_info[i].index, load_flags);
if (error) {
return geterror(error);
geterror(error);
goto glyph_error;
}

glyph_slot = self->face->glyph;
Expand All @@ -968,7 +975,8 @@ font_render(FontObject *self, PyObject *args) {
error = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, &origin, 1);
}
if (error) {
return geterror(error);
geterror(error);
goto glyph_error;
}

bitmap_glyph = (FT_BitmapGlyph)glyph;
Expand Down Expand Up @@ -1110,6 +1118,12 @@ font_render(FontObject *self, PyObject *args) {
return Py_BuildValue("O(ii)(ii)", image, width, height, x_offset, y_offset);

glyph_error:
if (im->destroy) {
im->destroy(im);
}
if (im->image) {
free(im->image);
}
if (stroker != NULL) {
FT_Done_Glyph(glyph);
}
Expand Down

0 comments on commit d64739f

Please sign in to comment.