[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [34473] trunk/blender/source/blender: Raise an exception when registering classes with ID names which are too long .

Campbell Barton ideasman42 at gmail.com
Mon Jan 24 04:38:35 CET 2011


Revision: 34473
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=34473
Author:   campbellbarton
Date:     2011-01-24 03:38:34 +0000 (Mon, 24 Jan 2011)
Log Message:
-----------
Raise an exception when registering classes with ID names which are too long. (related to bug ), found while looking into bug [#25776].

Modified Paths:
--------------
    trunk/blender/source/blender/makesrna/RNA_types.h
    trunk/blender/source/blender/makesrna/intern/rna_animation.c
    trunk/blender/source/blender/makesrna/intern/rna_render.c
    trunk/blender/source/blender/makesrna/intern/rna_ui.c
    trunk/blender/source/blender/makesrna/intern/rna_wm.c
    trunk/blender/source/blender/python/intern/bpy_rna.c

Modified: trunk/blender/source/blender/makesrna/RNA_types.h
===================================================================
--- trunk/blender/source/blender/makesrna/RNA_types.h	2011-01-24 02:56:23 UTC (rev 34472)
+++ trunk/blender/source/blender/makesrna/RNA_types.h	2011-01-24 03:38:34 UTC (rev 34473)
@@ -187,6 +187,12 @@
 	 * most common case is functions that return arrays where the array */
 	PROP_THICK_WRAP = 1<<23,
 
+	/* Reject values outside limits, use for python api only so far
+	 * this is for use when silently clamping string length will give
+	 * bad behavior later. Could also enforce this for INT's and other types.
+	 * note: currently no support for function arguments or non utf8 paths (filepaths) */
+	PROP_NEVER_CLAMP = 1<<26,
+
 	/* internal flags */
 	PROP_BUILTIN = 1<<7,
 	PROP_EXPORT = 1<<8,

Modified: trunk/blender/source/blender/makesrna/intern/rna_animation.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_animation.c	2011-01-24 02:56:23 UTC (rev 34472)
+++ trunk/blender/source/blender/makesrna/intern/rna_animation.c	2011-01-24 03:38:34 UTC (rev 34473)
@@ -458,7 +458,7 @@
 		
 	prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "idname");
-	RNA_def_property_flag(prop, PROP_REGISTER);
+	RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
 		
 	/* Name */
 	prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);

Modified: trunk/blender/source/blender/makesrna/intern/rna_render.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_render.c	2011-01-24 02:56:23 UTC (rev 34472)
+++ trunk/blender/source/blender/makesrna/intern/rna_render.c	2011-01-24 03:38:34 UTC (rev 34473)
@@ -271,7 +271,7 @@
 
 	prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->idname");
-	RNA_def_property_flag(prop, PROP_REGISTER);
+	RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
 
 	prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->name");

Modified: trunk/blender/source/blender/makesrna/intern/rna_ui.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_ui.c	2011-01-24 02:56:23 UTC (rev 34472)
+++ trunk/blender/source/blender/makesrna/intern/rna_ui.c	2011-01-24 03:38:34 UTC (rev 34473)
@@ -646,7 +646,7 @@
 	/* registration */
 	prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->idname");
-	RNA_def_property_flag(prop, PROP_REGISTER);
+	RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
 	RNA_def_property_ui_text(prop, "ID Name", "If this is set, the panel gets a custom ID, otherwise it takes the name of the class used to define the panel. For example, if the class name is \"OBJECT_PT_hello\", and bl_idname is not set by the script, then bl_idname = \"OBJECT_PT_hello\"");
 	
 	prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
@@ -708,7 +708,7 @@
 	/* registration */
 	prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->idname");
-	RNA_def_property_flag(prop, PROP_REGISTER);
+	RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
 	RNA_def_property_ui_text(prop, "ID Name", "If this is set, the header gets a custom ID, otherwise it takes the name of the class used to define the panel. For example, if the class name is \"OBJECT_HT_hello\", and bl_idname is not set by the script, then bl_idname = \"OBJECT_HT_hello\"");
 
 	prop= RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
@@ -758,7 +758,7 @@
 	/* registration */
 	prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->idname");
-	RNA_def_property_flag(prop, PROP_REGISTER);
+	RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
 	RNA_def_property_ui_text(prop, "ID Name", "If this is set, the menu gets a custom ID, otherwise it takes the name of the class used to define the panel. For example, if the class name is \"OBJECT_MT_hello\", and bl_idname is not set by the script, then bl_idname = \"OBJECT_MT_hello\"");
 
 	prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);

Modified: trunk/blender/source/blender/makesrna/intern/rna_wm.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_wm.c	2011-01-24 02:56:23 UTC (rev 34472)
+++ trunk/blender/source/blender/makesrna/intern/rna_wm.c	2011-01-24 03:38:34 UTC (rev 34473)
@@ -867,6 +867,14 @@
 		return NULL;
 	}
 
+	/* sanity check on name
+	 * foo.bar */
+//	{
+//		char *ch;
+//		for(ch=identifier)
+
+//	}
+
 	/* check if we have registered this operator type before, and remove it */
 	{
 		wmOperatorType *ot= WM_operatortype_find(dummyot.idname, TRUE);
@@ -1121,10 +1129,10 @@
 	/* Registration */
 	prop= RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
 	RNA_def_property_string_sdna(prop, NULL, "type->idname");
-	RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
+	RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME-3); /* else it uses the pointer size!. -3 because '.' -> '_OT_' */
 	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
 	// RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-	RNA_def_property_flag(prop, PROP_REGISTER);
+	RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
 	RNA_def_struct_name_property(srna, prop);
 
 	prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
@@ -1185,7 +1193,7 @@
 	RNA_def_property_string_maxlength(prop, OP_MAX_TYPENAME); /* else it uses the pointer size! */
 	RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Operator_bl_idname_set");
 	// RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-	RNA_def_property_flag(prop, PROP_REGISTER);
+	RNA_def_property_flag(prop, PROP_REGISTER|PROP_NEVER_CLAMP);
 	RNA_def_struct_name_property(srna, prop);
 
 	prop= RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);

Modified: trunk/blender/source/blender/python/intern/bpy_rna.c
===================================================================
--- trunk/blender/source/blender/python/intern/bpy_rna.c	2011-01-24 02:56:23 UTC (rev 34472)
+++ trunk/blender/source/blender/python/intern/bpy_rna.c	2011-01-24 03:38:34 UTC (rev 34473)
@@ -1071,17 +1071,19 @@
 		case PROP_STRING:
 		{
 			const char *param;
+			Py_ssize_t param_size= 0;
 #ifdef USE_STRING_COERCE
 			PyObject *value_coerce= NULL;
 			int subtype= RNA_property_subtype(prop);
 			if(ELEM3(subtype, PROP_FILEPATH, PROP_DIRPATH, PROP_FILENAME)) {
+				/* TODO, get size */
 				param= PyC_UnicodeAsByte(value, &value_coerce);
 			}
 			else {
-				param= _PyUnicode_AsString(value);
+				param= _PyUnicode_AsStringAndSize(value, &param_size);
 			}
 #else // USE_STRING_COERCE
-			param= _PyUnicode_AsString(value);
+			param= _PyUnicode_AsStringAndSize(value, &param_size);
 #endif // USE_STRING_COERCE
 
 			if (param==NULL) {
@@ -1090,7 +1092,19 @@
 			}
 			else {
 				if(data)	*((char**)data)= (char *)param; /*XXX, this is suspect but needed for function calls, need to see if theres a better way */
-				else		RNA_property_string_set(ptr, prop, param);
+				else {
+					if(RNA_property_flag(prop) & PROP_NEVER_CLAMP) {
+						int param_size_max= RNA_property_string_maxlength(prop);
+						if(param_size > param_size_max) {
+							PyErr_Format(PyExc_TypeError, "%.200s %.200s.%.200s only supports a string of length %d, found %d", error_prefix, RNA_struct_identifier(ptr->type), RNA_property_identifier(prop), param_size, param_size_max);
+							return -1;
+						}
+#ifdef USE_STRING_COERCE
+						Py_XDECREF(value_coerce);
+#endif // USE_STRING_COERCE
+					}
+					RNA_property_string_set(ptr, prop, param);
+				}
 			}
 #ifdef USE_STRING_COERCE
 			Py_XDECREF(value_coerce);




More information about the Bf-blender-cvs mailing list