== 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).
This commit is contained in:
Willian Padovani Germano 2008-05-01 22:28:18 +00:00
parent d99ddc5cf8
commit 9ea5788c37
3 changed files with 19 additions and 6 deletions

@ -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;

@ -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};

@ -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;
}