mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-10 19:56:47 +03:00
Check type of items passed into to ImageCms.ImageCmsProfile, fixes #2037
This commit is contained in:
parent
2178da8ec2
commit
1d068b6e0a
|
@ -162,8 +162,11 @@ class ImageCmsProfile(object):
|
|||
self._set(core.profile_open(profile), profile)
|
||||
elif hasattr(profile, "read"):
|
||||
self._set(core.profile_frombytes(profile.read()))
|
||||
elif isinstance(profile, _imagingcms.CmsProfile):
|
||||
self._set(profile)
|
||||
else:
|
||||
self._set(profile) # assume it's already a profile
|
||||
raise TypeError("Invalid type for Profile")
|
||||
|
||||
|
||||
def _set(self, profile, filename=None):
|
||||
self.profile = profile
|
||||
|
|
|
@ -321,5 +321,17 @@ class TestImageCms(PillowTestCase):
|
|||
self.assertEqual(p.viewing_condition, 'Reference Viewing Condition in IEC 61966-2-1')
|
||||
self.assertEqual(p.xcolor_space, 'RGB ')
|
||||
|
||||
def test_profile_typesafety(self):
|
||||
""" Profile init type safety
|
||||
|
||||
prepatch, these would segfault, postpatch they should emit a typeerror
|
||||
"""
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
ImageCms.ImageCmsProfile(0).tobytes()
|
||||
with self.assertRaises(TypeError):
|
||||
ImageCms.ImageCmsProfile(1).tobytes()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
|
@ -1378,7 +1378,8 @@ static struct PyGetSetDef cms_profile_getsetters[] = {
|
|||
|
||||
static PyTypeObject CmsProfile_Type = {
|
||||
PyVarObject_HEAD_INIT(NULL, 0)
|
||||
"CmsProfile", sizeof(CmsProfileObject), 0,
|
||||
"PIL._imagingcms.CmsProfile", /*tp_name */
|
||||
sizeof(CmsProfileObject), 0,/*tp_basicsize, tp_itemsize */
|
||||
/* methods */
|
||||
(destructor) cms_profile_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
|
@ -1470,10 +1471,15 @@ setup_module(PyObject* m) {
|
|||
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
CmsProfile_Type.tp_new = PyType_GenericNew;
|
||||
|
||||
/* Ready object types */
|
||||
PyType_Ready(&CmsProfile_Type);
|
||||
PyType_Ready(&CmsTransform_Type);
|
||||
|
||||
Py_INCREF(&CmsProfile_Type);
|
||||
PyModule_AddObject(m, "CmsProfile", (PyObject *)&CmsProfile_Type);
|
||||
|
||||
d = PyModule_GetDict(m);
|
||||
|
||||
v = PyUnicode_FromFormat("%d.%d", LCMS_VERSION / 100, LCMS_VERSION % 100);
|
||||
|
@ -1499,7 +1505,7 @@ PyInit__imagingcms(void) {
|
|||
|
||||
if (setup_module(m) < 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
PyDateTime_IMPORT;
|
||||
|
||||
return m;
|
||||
|
|
Loading…
Reference in New Issue
Block a user