[Bf-blender-cvs] [037b771e1af] blender-v3.4-release: Fix crash building Python API docs

Campbell Barton noreply at git.blender.org
Sat Nov 5 10:03:33 CET 2022


Commit: 037b771e1af53b0f87b73a9fe01e8e660267ec81
Author: Campbell Barton
Date:   Sat Nov 5 19:57:02 2022 +1100
Branches: blender-v3.4-release
https://developer.blender.org/rB037b771e1af53b0f87b73a9fe01e8e660267ec81

Fix crash building Python API docs

Color space conversion item-function missed checking the context was
NULL to return a static array. This caused freed memory access when
building docs.

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

M	source/blender/makesrna/RNA_enum_items.h
M	source/blender/makesrna/intern/rna_color.c
M	source/blender/makesrna/intern/rna_nodetree.c

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

diff --git a/source/blender/makesrna/RNA_enum_items.h b/source/blender/makesrna/RNA_enum_items.h
index 53241c4a809..1604bd97ed4 100644
--- a/source/blender/makesrna/RNA_enum_items.h
+++ b/source/blender/makesrna/RNA_enum_items.h
@@ -19,6 +19,7 @@ DEF_ENUM(rna_enum_object_empty_drawtype_items)
 DEF_ENUM(rna_enum_object_gpencil_type_items)
 DEF_ENUM(rna_enum_metaelem_type_items)
 
+DEF_ENUM(rna_enum_color_space_convert_default_items)
 DEF_ENUM(rna_enum_proportional_falloff_items)
 DEF_ENUM(rna_enum_proportional_falloff_curve_only_items)
 DEF_ENUM(rna_enum_snap_source_items)
diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c
index b68d87587e7..061ddc034b0 100644
--- a/source/blender/makesrna/intern/rna_color.c
+++ b/source/blender/makesrna/intern/rna_color.c
@@ -15,11 +15,22 @@
 #include "BKE_node_tree_update.h"
 
 #include "RNA_define.h"
+#include "RNA_enum_types.h"
 #include "rna_internal.h"
 
 #include "WM_api.h"
 #include "WM_types.h"
 
+const EnumPropertyItem rna_enum_color_space_convert_default_items[] = {
+    {0,
+     "NONE",
+     0,
+     "None",
+     "Do not perform any color transform on load, treat colors as in scene linear space "
+     "already"},
+    {0, NULL, 0, NULL, NULL},
+};
+
 #ifdef RNA_RUNTIME
 
 #  include "RNA_access.h"
@@ -566,8 +577,11 @@ static void rna_ColorManagedColorspaceSettings_colorspace_set(struct PointerRNA
 }
 
 static const EnumPropertyItem *rna_ColorManagedColorspaceSettings_colorspace_itemf(
-    bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
+    bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
+  if (C == NULL) {
+    return rna_enum_color_space_convert_default_items;
+  }
   EnumPropertyItem *items = NULL;
   int totitem = 0;
 
@@ -1190,16 +1204,6 @@ static void rna_def_colormanage(BlenderRNA *brna)
       {0, NULL, 0, NULL, NULL},
   };
 
-  static const EnumPropertyItem color_space_items[] = {
-      {0,
-       "NONE",
-       0,
-       "None",
-       "Do not perform any color transform on load, treat colors as in scene linear space "
-       "already"},
-      {0, NULL, 0, NULL, NULL},
-  };
-
   /* ** Display Settings ** */
   srna = RNA_def_struct(brna, "ColorManagedDisplaySettings", NULL);
   RNA_def_struct_path_func(srna, "rna_ColorManagedDisplaySettings_path");
@@ -1279,7 +1283,7 @@ static void rna_def_colormanage(BlenderRNA *brna)
   prop = RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
   RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
   RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-  RNA_def_property_enum_items(prop, color_space_items);
+  RNA_def_property_enum_items(prop, rna_enum_color_space_convert_default_items);
   RNA_def_property_enum_funcs(prop,
                               "rna_ColorManagedColorspaceSettings_colorspace_get",
                               "rna_ColorManagedColorspaceSettings_colorspace_set",
@@ -1309,7 +1313,7 @@ static void rna_def_colormanage(BlenderRNA *brna)
 
   prop = RNA_def_property(srna, "name", PROP_ENUM, PROP_NONE);
   RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
-  RNA_def_property_enum_items(prop, color_space_items);
+  RNA_def_property_enum_items(prop, rna_enum_color_space_convert_default_items);
   RNA_def_property_enum_funcs(prop,
                               "rna_ColorManagedColorspaceSettings_colorspace_get",
                               "rna_ColorManagedColorspaceSettings_colorspace_set",
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 7457267a83c..4460a8c8830 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -4500,8 +4500,11 @@ static void rna_NodeConvertColorSpace_to_color_space_set(struct PointerRNA *ptr,
 }
 
 static const EnumPropertyItem *rna_NodeConvertColorSpace_color_space_itemf(
-    bContext *UNUSED(C), PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
+    bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
 {
+  if (C == NULL) {
+    return rna_enum_color_space_convert_default_items;
+  }
   EnumPropertyItem *items = NULL;
   int totitem = 0;
 
@@ -7323,19 +7326,9 @@ static void def_cmp_convert_color_space(StructRNA *srna)
   PropertyRNA *prop;
   RNA_def_struct_sdna_from(srna, "NodeConvertColorSpace", "storage");
 
-  static const EnumPropertyItem color_space_items[] = {
-      {0,
-       "NONE",
-       0,
-       "None",
-       "Do not perform any color transform on load, treat colors as in scene linear space "
-       "already"},
-      {0, NULL, 0, NULL, NULL},
-  };
-
   prop = RNA_def_property(srna, "from_color_space", PROP_ENUM, PROP_NONE);
   RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
-  RNA_def_property_enum_items(prop, color_space_items);
+  RNA_def_property_enum_items(prop, rna_enum_color_space_convert_default_items);
   RNA_def_property_enum_funcs(prop,
                               "rna_NodeConvertColorSpace_from_color_space_get",
                               "rna_NodeConvertColorSpace_from_color_space_set",
@@ -7345,7 +7338,7 @@ static void def_cmp_convert_color_space(StructRNA *srna)
 
   prop = RNA_def_property(srna, "to_color_space", PROP_ENUM, PROP_NONE);
   RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
-  RNA_def_property_enum_items(prop, color_space_items);
+  RNA_def_property_enum_items(prop, rna_enum_color_space_convert_default_items);
   RNA_def_property_enum_funcs(prop,
                               "rna_NodeConvertColorSpace_to_color_space_get",
                               "rna_NodeConvertColorSpace_to_color_space_set",



More information about the Bf-blender-cvs mailing list