From 3adc3a13708a943e345e969e9d2847b4c0fb99b5 Mon Sep 17 00:00:00 2001 From: Nathan Vegdahl Date: Tue, 18 Apr 2023 16:38:54 +0200 Subject: [PATCH] Fix: segfault when indexing into some collections with strings. This happens when the collection's item type doesn't have a 'nameproperty' to index with. For debug builds we error out with an assert, since in general this shouldn't happen. For release builds Python will report item not found. --- source/blender/python/intern/bpy_rna.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c index 858e4de2601..77a9e52cd56 100644 --- a/source/blender/python/intern/bpy_rna.c +++ b/source/blender/python/intern/bpy_rna.c @@ -2371,6 +2371,13 @@ static PyObject *pyrna_prop_collection_subscript_str(BPy_PropertyRNA *self, cons RNA_property_collection_begin(&self->ptr, self->prop, &iter); for (int i = 0; iter.valid; RNA_property_collection_next(&iter), i++) { PropertyRNA *nameprop = RNA_struct_name_property(iter.ptr.type); + BLI_assert_msg( + nameprop, + "Attempted to use a string to index into a collection of items with no 'nameproperty'."); + if (nameprop == NULL) { + // For non-debug builds, bail if there's no 'nameproperty' to check. + break; + } char *nameptr = RNA_property_string_get_alloc( &iter.ptr, nameprop, name, sizeof(name), &namelen); if ((keylen == namelen) && STREQ(nameptr, keyname)) { -- 2.30.2