Fix: segfault when indexing into some collections with strings. #107086

Merged
Nathan Vegdahl merged 1 commits from nathanvegdahl/blender:str_collection_indexing_bug into main 2023-04-18 17:15:34 +02:00
1 changed files with 7 additions and 0 deletions

View File

@ -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.
Review

Blender uses /* */ comment style, see https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments

Blender uses `/* */` comment style, see https://wiki.blender.org/wiki/Style_Guide/C_Cpp#Comments
Review

Gah! Sorry, I didn't refresh the page between Bastien's approval and merging, and missed your comment. Thanks for letting me know. I'll fix it.

Gah! Sorry, I didn't refresh the page between Bastien's approval and merging, and missed your comment. Thanks for letting me know. I'll fix it.
break;
}
char *nameptr = RNA_property_string_get_alloc(
&iter.ptr, nameprop, name, sizeof(name), &namelen);
if ((keylen == namelen) && STREQ(nameptr, keyname)) {