Fixed crash when loading non-font bytes

This commit is contained in:
Andrew Murray 2019-06-23 11:53:01 +10:00
parent 32d10505a3
commit 7bb16de81c
3 changed files with 7 additions and 0 deletions

View File

@ -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.'

View File

@ -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 = []

View File

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