mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-26 17:24:31 +03:00
Fixed crash when loading non-font bytes
This commit is contained in:
parent
32d10505a3
commit
7bb16de81c
|
@ -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