mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #3912 from radarhere/non_font_bytes
Fixed crash when loading non-font bytes
This commit is contained in:
		
						commit
						b584635a8c
					
				| 
						 | 
				
			
			@ -420,6 +420,10 @@ class TestImageFont(PillowTestCase):
 | 
			
		|||
        self.assertRaises(IOError, ImageFont.load_path, filename)
 | 
			
		||||
        self.assertRaises(IOError, ImageFont.truetype, filename)
 | 
			
		||||
 | 
			
		||||
    def test_load_non_font_bytes(self):
 | 
			
		||||
        with open("Tests/images/hopper.jpg", "rb") as f:
 | 
			
		||||
            self.assertRaises(IOError, ImageFont.truetype, f)
 | 
			
		||||
 | 
			
		||||
    def test_default_font(self):
 | 
			
		||||
        # Arrange
 | 
			
		||||
        txt = 'This is a "better than nothing" default font.'
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -545,6 +545,8 @@ def truetype(font=None, size=10, index=0, encoding="", layout_engine=None):
 | 
			
		|||
    try:
 | 
			
		||||
        return freetype(font)
 | 
			
		||||
    except IOError:
 | 
			
		||||
        if not isPath(font):
 | 
			
		||||
            raise
 | 
			
		||||
        ttf_filename = os.path.basename(font)
 | 
			
		||||
 | 
			
		||||
        dirs = []
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -315,6 +315,7 @@ getfont(PyObject* self_, PyObject* args, PyObject* kw)
 | 
			
		|||
    if (error) {
 | 
			
		||||
        if (self->font_bytes) {
 | 
			
		||||
            PyMem_Free(self->font_bytes);
 | 
			
		||||
            self->font_bytes = NULL;
 | 
			
		||||
        }
 | 
			
		||||
        Py_DECREF(self);
 | 
			
		||||
        return geterror(error);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user