Merge pull request #7218 from radarhere/null

This commit is contained in:
Hugo van Kemenade 2023-06-18 21:50:46 +03:00 committed by GitHub
commit d64739f4d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 5 deletions

View File

@ -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):

View File

@ -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;
@ -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(
@ -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;
@ -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;
@ -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;
@ -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);
}