== PyNodes ==
authorWillian Padovani Germano <wpgermano@gmail.com>
Thu, 1 May 2008 22:28:18 +0000 (22:28 +0000)
committerWillian Padovani Germano <wpgermano@gmail.com>
Thu, 1 May 2008 22:28:18 +0000 (22:28 +0000)
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
source/blender/blenkernel/intern/node.c
source/blender/python/api2_2x/Node.c

index 76581e4f34f499d8c978b2cbab7bc8e1ebbc7de6..b3b68a9b3ff21c5c9bb04be75433909578957ecb 100644 (file)
@@ -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;
index 6c3775bcbaacd64cdbe281d2fde26f55174f1d94..28c3e1c64e6f5b91a39ced6e2cce28cc6c88e1bd 100644 (file)
@@ -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};
index 80b45bb22970ff744172e64572815f55f464826c..24df6de66ccf62f6f34f9256ae4375795a007e5b 100644 (file)
@@ -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;
 }