diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-01-04 12:00:58 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-01-04 12:05:32 +0300 |
commit | b8e536f3819155f1ed5dfae45bad261b6c328e20 (patch) | |
tree | a9901cc3690bb77198f0d0d32f548c3665a96502 /source/blender/python/generic | |
parent | a6285339ba75063d61631940a2bad7003e31b4b9 (diff) |
Fix imbuf.new & resize allowing zero & negative dimensions
Diffstat (limited to 'source/blender/python/generic')
-rw-r--r-- | source/blender/python/generic/imbuf_py_api.c | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/source/blender/python/generic/imbuf_py_api.c b/source/blender/python/generic/imbuf_py_api.c index 7247c17c406..24029f0ca12 100644 --- a/source/blender/python/generic/imbuf_py_api.c +++ b/source/blender/python/generic/imbuf_py_api.c @@ -93,7 +93,7 @@ static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw) { PY_IMBUF_CHECK_OBJ(self); - uint size[2]; + int size[2]; enum { FAST, BILINEAR }; const struct PyC_StringEnumItems method_items[] = { @@ -104,11 +104,16 @@ static PyObject *py_imbuf_resize(Py_ImBuf *self, PyObject *args, PyObject *kw) struct PyC_StringEnum method = {method_items, FAST}; static const char *_keywords[] = {"size", "method", NULL}; - static _PyArg_Parser _parser = {"(II)|O&:resize", _keywords, 0}; + static _PyArg_Parser _parser = {"(ii)|O&:resize", _keywords, 0}; if (!_PyArg_ParseTupleAndKeywordsFast( args, kw, &_parser, &size[0], &size[1], PyC_ParseStringEnum, &method)) { return NULL; } + if (size[0] <= 0 || size[1] <= 0) { + PyErr_Format(PyExc_ValueError, "resize: Image size cannot be below 1 (%d, %d)", UNPACK2(size)); + return NULL; + } + if (method.value_found == FAST) { IMB_scalefastImBuf(self->ibuf, UNPACK2(size)); } @@ -427,6 +432,10 @@ static PyObject *M_imbuf_new(PyObject *UNUSED(self), PyObject *args, PyObject *k if (!_PyArg_ParseTupleAndKeywordsFast(args, kw, &_parser, &size[0], &size[1])) { return NULL; } + if (size[0] <= 0 || size[1] <= 0) { + PyErr_Format(PyExc_ValueError, "new: Image size cannot be below 1 (%d, %d)", UNPACK2(size)); + return NULL; + } /* TODO, make options */ const uchar planes = 4; |