mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-27 18:36:17 +03:00
Merge pull request #3098 from uploadcare/getlist-fixes
Raise error if it is occurred during conversion in getlist
This commit is contained in:
commit
9d404e9979
|
@ -66,6 +66,14 @@ class TestColorLut3DCoreAPI(PillowTestCase):
|
|||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, [0, 0, 0] * 9)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, [0, 0, "0"] * 8)
|
||||
|
||||
with self.assertRaises(TypeError):
|
||||
im.im.color_lut_3d('RGB', Image.LINEAR,
|
||||
3, 2, 2, 2, 16)
|
||||
|
||||
def test_correct_args(self):
|
||||
im = Image.new('RGB', (10, 10), 0)
|
||||
|
||||
|
|
|
@ -379,12 +379,12 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
|||
PyObject* seq;
|
||||
PyObject* op;
|
||||
|
||||
if (!PySequence_Check(arg)) {
|
||||
if ( ! PySequence_Check(arg)) {
|
||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
n = PyObject_Length(arg);
|
||||
n = PySequence_Size(arg);
|
||||
if (length && wrong_length && n != *length) {
|
||||
PyErr_SetString(PyExc_ValueError, wrong_length);
|
||||
return NULL;
|
||||
|
@ -393,13 +393,12 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
|||
/* malloc check ok, type & ff is just a sizeof(something)
|
||||
calloc checks for overflow */
|
||||
list = calloc(n, type & 0xff);
|
||||
if (!list)
|
||||
if ( ! list)
|
||||
return PyErr_NoMemory();
|
||||
|
||||
seq = PySequence_Fast(arg, must_be_sequence);
|
||||
if (!seq) {
|
||||
if ( ! seq) {
|
||||
free(list);
|
||||
PyErr_SetString(PyExc_TypeError, must_be_sequence);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -427,12 +426,16 @@ getlist(PyObject* arg, Py_ssize_t* length, const char* wrong_length, int type)
|
|||
}
|
||||
}
|
||||
|
||||
Py_DECREF(seq);
|
||||
|
||||
if (PyErr_Occurred()) {
|
||||
free(list);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (length)
|
||||
*length = n;
|
||||
|
||||
PyErr_Clear();
|
||||
Py_DECREF(seq);
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user