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

Fixed deallocating mask images #7246

Merged
merged 1 commit into from
Jul 1, 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
12 changes: 10 additions & 2 deletions src/PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,9 +562,17 @@ def getmask2(
_string_length_check(text)
if start is None:
start = (0, 0)
im, size, offset = self.font.render(
im = None

def fill(mode, size):
nonlocal im

im = Image.core.fill(mode, size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to move the decompression bomb check here to simplify the C function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created #7247 for this.

return im

size, offset = self.font.render(
text,
Image.core.fill,
fill,
mode,
direction,
features,
Expand Down
7 changes: 4 additions & 3 deletions src/_imagingft.c
Original file line number Diff line number Diff line change
Expand Up @@ -882,7 +882,7 @@ font_render(FontObject *self, PyObject *args) {
if (max_image_pixels != Py_None) {
if ((long long)(width > 1 ? width : 1) * (height > 1 ? height : 1) > PyLong_AsLongLong(max_image_pixels) * 2) {
PyMem_Del(glyph_info);
return Py_BuildValue("O(ii)(ii)", Py_None, width, height, 0, 0);
return Py_BuildValue("(ii)(ii)", width, height, 0, 0);
}
}

Expand All @@ -898,7 +898,7 @@ font_render(FontObject *self, PyObject *args) {
y_offset -= stroke_width;
if (count == 0 || width == 0 || height == 0) {
PyMem_Del(glyph_info);
return Py_BuildValue("O(ii)(ii)", image, width, height, x_offset, y_offset);
return Py_BuildValue("(ii)(ii)", width, height, x_offset, y_offset);
}

if (stroke_width) {
Expand Down Expand Up @@ -1113,9 +1113,10 @@ font_render(FontObject *self, PyObject *args) {
if (bitmap_converted_ready) {
FT_Bitmap_Done(library, &bitmap_converted);
}
Py_DECREF(image);
FT_Stroker_Done(stroker);
PyMem_Del(glyph_info);
return Py_BuildValue("O(ii)(ii)", image, width, height, x_offset, y_offset);
return Py_BuildValue("(ii)(ii)", width, height, x_offset, y_offset);

glyph_error:
if (im->destroy) {
Expand Down