mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #7645 from nulano/font-bomb
Simplify FreeTypeFont.render
This commit is contained in:
		
						commit
						f71cfec76f
					
				| 
						 | 
				
			
			@ -584,22 +584,13 @@ class FreeTypeFont:
 | 
			
		|||
        _string_length_check(text)
 | 
			
		||||
        if start is None:
 | 
			
		||||
            start = (0, 0)
 | 
			
		||||
        im = None
 | 
			
		||||
        size = None
 | 
			
		||||
 | 
			
		||||
        def fill(width, height):
 | 
			
		||||
            nonlocal im, size
 | 
			
		||||
 | 
			
		||||
            size = (width, height)
 | 
			
		||||
            if Image.MAX_IMAGE_PIXELS is not None:
 | 
			
		||||
                pixels = max(1, width) * max(1, height)
 | 
			
		||||
                if pixels > 2 * Image.MAX_IMAGE_PIXELS:
 | 
			
		||||
                    return
 | 
			
		||||
            Image._decompression_bomb_check(size)
 | 
			
		||||
            return Image.core.fill("RGBA" if mode == "RGBA" else "L", size)
 | 
			
		||||
 | 
			
		||||
            im = Image.core.fill("RGBA" if mode == "RGBA" else "L", size)
 | 
			
		||||
            return im
 | 
			
		||||
 | 
			
		||||
        offset = self.font.render(
 | 
			
		||||
        return self.font.render(
 | 
			
		||||
            text,
 | 
			
		||||
            fill,
 | 
			
		||||
            mode,
 | 
			
		||||
| 
						 | 
				
			
			@ -612,8 +603,6 @@ class FreeTypeFont:
 | 
			
		|||
            start[0],
 | 
			
		||||
            start[1],
 | 
			
		||||
        )
 | 
			
		||||
        Image._decompression_bomb_check(size)
 | 
			
		||||
        return im, offset
 | 
			
		||||
 | 
			
		||||
    def font_variant(
 | 
			
		||||
        self, font=None, size=None, index=None, encoding=None, layout_engine=None
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -880,7 +880,7 @@ font_render(FontObject *self, PyObject *args) {
 | 
			
		|||
    image = PyObject_CallFunction(fill, "ii", width, height);
 | 
			
		||||
    if (image == Py_None) {
 | 
			
		||||
        PyMem_Del(glyph_info);
 | 
			
		||||
        return Py_BuildValue("ii", 0, 0);
 | 
			
		||||
        return Py_BuildValue("N(ii)", image, 0, 0);
 | 
			
		||||
    } else if (image == NULL) {
 | 
			
		||||
        PyMem_Del(glyph_info);
 | 
			
		||||
        return NULL;
 | 
			
		||||
| 
						 | 
				
			
			@ -894,7 +894,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("ii", x_offset, y_offset);
 | 
			
		||||
        return Py_BuildValue("N(ii)", image, x_offset, y_offset);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (stroke_width) {
 | 
			
		||||
| 
						 | 
				
			
			@ -1130,18 +1130,12 @@ 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("ii", x_offset, y_offset);
 | 
			
		||||
    return Py_BuildValue("N(ii)", image, x_offset, y_offset);
 | 
			
		||||
 | 
			
		||||
glyph_error:
 | 
			
		||||
    if (im->destroy) {
 | 
			
		||||
        im->destroy(im);
 | 
			
		||||
    }
 | 
			
		||||
    if (im->image) {
 | 
			
		||||
        free(im->image);
 | 
			
		||||
    }
 | 
			
		||||
    Py_DECREF(image);
 | 
			
		||||
    if (stroker != NULL) {
 | 
			
		||||
        FT_Done_Glyph(glyph);
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user