Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved checks in font_render #7218

Merged
merged 5 commits into from Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file not shown.
1 change: 1 addition & 0 deletions Tests/test_imagefont.py
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
Expand Up @@ -880,13 +880,17 @@
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;

Check warning on line 892 in src/_imagingft.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingft.c#L891-L892

Added lines #L891 - L892 were not covered by tests
}
id = PyLong_AsSsize_t(PyObject_GetAttrString(image, "id"));
im = (Imaging)id;

Expand All @@ -900,7 +904,8 @@
if (stroke_width) {
error = FT_Stroker_New(library, &stroker);
if (error) {
return geterror(error);
geterror(error);
goto glyph_error;

Check warning on line 908 in src/_imagingft.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingft.c#L907-L908

Added lines #L907 - L908 were not covered by tests
}

FT_Stroker_Set(
Expand All @@ -923,7 +928,8 @@
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;

Check warning on line 932 in src/_imagingft.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingft.c#L931-L932

Added lines #L931 - L932 were not covered by tests
}

glyph_slot = self->face->glyph;
Expand Down Expand Up @@ -954,7 +960,8 @@

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

Check warning on line 964 in src/_imagingft.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingft.c#L963-L964

Added lines #L963 - L964 were not covered by tests
}

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

Check warning on line 979 in src/_imagingft.c

View check run for this annotation

Codecov / codecov/patch

src/_imagingft.c#L978-L979

Added lines #L978 - L979 were not covered by tests
}

bitmap_glyph = (FT_BitmapGlyph)glyph;
Expand Down Expand Up @@ -1110,6 +1118,12 @@
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