[Bf-blender-cvs] [b8e536f3819] master: Fix imbuf.new & resize allowing zero & negative dimensions

Campbell Barton noreply at git.blender.org
Mon Jan 4 10:06:10 CET 2021


Commit: b8e536f3819155f1ed5dfae45bad261b6c328e20
Author: Campbell Barton
Date:   Mon Jan 4 20:00:58 2021 +1100
Branches: master
https://developer.blender.org/rBb8e536f3819155f1ed5dfae45bad261b6c328e20

Fix imbuf.new & resize allowing zero & negative dimensions

===================================================================

M	source/blender/python/generic/imbuf_py_api.c

===================================================================

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;



More information about the Bf-blender-cvs mailing list