From 9ea5788c37ccd95906066a51ebcbdecc65c5f62d Mon Sep 17 00:00:00 2001 From: Willian Padovani Germano Date: Thu, 1 May 2008 22:28:18 +0000 Subject: [PATCH] == PyNodes == Bug #10104 reported by bebraw: missing check for how many node sockets were being created by a pynode script. Too many (more than MAX_SOCKET == 64) would crash Blender. http://projects.blender.org/tracker/?func=detail&atid=125&aid=10104&group_id=9 Notes: moved the MAX_SOCKET define from node.c to BKE_node.h so I could use it in Node.c. Also improved error reporting in pynodes when errors occur in the init stage. Thanks Juho (bebraw), Tom (assigned the bug to me) and Brecht (mentioned the MAX_SOCKET define). --- source/blender/blenkernel/BKE_node.h | 3 ++- source/blender/blenkernel/intern/node.c | 3 --- source/blender/python/api2_2x/Node.c | 19 +++++++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h index 76581e4f34f..b3b68a9b3ff 100644 --- a/source/blender/blenkernel/BKE_node.h +++ b/source/blender/blenkernel/BKE_node.h @@ -33,7 +33,8 @@ #ifndef BKE_NODE_H #define BKE_NODE_H - +/* not very important, but the stack solver likes to know a maximum */ +#define MAX_SOCKET 64 struct ID; struct bNodeTree; diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c index 6c3775bcbaa..28c3e1c64e6 100644 --- a/source/blender/blenkernel/intern/node.c +++ b/source/blender/blenkernel/intern/node.c @@ -68,9 +68,6 @@ #include "SHD_node.h" -/* not very important, but the stack solver likes to know a maximum */ -#define MAX_SOCKET 64 - static ListBase empty_list = {NULL, NULL}; ListBase node_all_composit = {NULL, NULL}; ListBase node_all_shaders = {NULL, NULL}; diff --git a/source/blender/python/api2_2x/Node.c b/source/blender/python/api2_2x/Node.c index 80b45bb2297..24df6de66cc 100644 --- a/source/blender/python/api2_2x/Node.c +++ b/source/blender/python/api2_2x/Node.c @@ -361,6 +361,15 @@ static int pysockets_to_blendersockets(PyObject *tuple, bNodeSocketType **socks, len = PyTuple_Size(tuple); + if (len >= MAX_SOCKET) { + char error_msg[70]; + PyOS_snprintf(error_msg, sizeof(error_msg), + "limit exceeded: each node can't have more than %d i/o sockets", MAX_SOCKET - 1); + PyErr_SetString(PyExc_AttributeError, error_msg); + len = 0; + retval = -1; + } + nsocks = MEM_callocN(sizeof(bNodeSocketType)*(len+1), "bNodeSocketType in Node.c"); for (pos = 0, a = 0; pos< len; pos++, a++) { @@ -437,6 +446,7 @@ static int Map_socketdef(BPy_NodeSocketLists *self, PyObject *args, void *closur { bNode *node = NULL; PyObject *tuple = NULL; + int ret = 0; node = self->node; @@ -453,7 +463,7 @@ static int Map_socketdef(BPy_NodeSocketLists *self, PyObject *args, void *closur if (args) { if(PySequence_Check(args)) { tuple = PySequence_Tuple(args); - pysockets_to_blendersockets(tuple, + ret = pysockets_to_blendersockets(tuple, &(node->typeinfo->inputs), node->custom1, 1); Py_DECREF(self->input); self->input = tuple; @@ -466,7 +476,7 @@ static int Map_socketdef(BPy_NodeSocketLists *self, PyObject *args, void *closur if (args) { if(PyList_Check(args)) { tuple = PySequence_Tuple(args); - pysockets_to_blendersockets(tuple, + ret = pysockets_to_blendersockets(tuple, &(node->typeinfo->outputs), node->custom1, 0); Py_DECREF(self->output); self->output = tuple; @@ -479,6 +489,11 @@ static int Map_socketdef(BPy_NodeSocketLists *self, PyObject *args, void *closur fprintf(stderr,"DEBUG pynodes: got no list in Map_socketdef\n"); break; } + + if (ret == -1) { + node->custom1 = BSET(node->custom1, NODE_DYNAMIC_ERROR); + } + return 0; }