Fix #107416: Check length of Property Collection before type

In edit mode the uv map data length gets set to zero. The specialized
MLoopUV code used to have a check to detect this when trying to access
the UVs using foreach_get/set . Add this check for the Attribute code
path as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/109179
This commit is contained in:
Martijn Versteegh
2023-07-05 20:06:18 +02:00
committed by Martijn Versteegh
parent 0b7d8a20bf
commit a280e8a68c

View File

@@ -5287,10 +5287,8 @@ static int foreach_parse_args(BPy_PropertyRNA *self,
int *r_attr_tot,
bool *r_attr_signed)
{
#if 0
int array_tot;
int target_tot;
#endif
*r_size = *r_attr_tot = 0;
*r_attr_signed = false;
@@ -5312,6 +5310,19 @@ static int foreach_parse_args(BPy_PropertyRNA *self,
*r_tot = PySequence_Size(*r_seq);
if (*r_tot > 0) {
if (RNA_property_type(self->prop) == PROP_COLLECTION) {
array_tot = RNA_property_collection_length(&self->ptr, self->prop);
}
else {
array_tot = RNA_property_array_length(&self->ptr, self->prop);
}
if (array_tot == 0) {
PyErr_Format(PyExc_TypeError,
"foreach_get(attr, sequence) sequence length mismatch given %d, needed 0",
*r_tot);
return -1;
}
if (!foreach_attr_type(self, *r_attr, r_raw_type, r_attr_tot, r_attr_signed)) {
PyErr_Format(PyExc_AttributeError,
"foreach_get/set '%.200s.%200s[...]' elements have no attribute '%.200s'",
@@ -5322,19 +5333,10 @@ static int foreach_parse_args(BPy_PropertyRNA *self,
}
*r_size = RNA_raw_type_sizeof(*r_raw_type);
#if 0 /* Works fine, but not strictly needed. \
* we could allow RNA_property_collection_raw_* to do the checks */
if ((*r_attr_tot) < 1) {
*r_attr_tot = 1;
}
if (RNA_property_type(self->prop) == PROP_COLLECTION) {
array_tot = RNA_property_collection_length(&self->ptr, self->prop);
}
else {
array_tot = RNA_property_array_length(&self->ptr, self->prop);
}
target_tot = array_tot * (*r_attr_tot);
/* rna_access.cc - rna_raw_access(...) uses this same method. */
@@ -5345,7 +5347,6 @@ static int foreach_parse_args(BPy_PropertyRNA *self,
target_tot);
return -1;
}
#endif
}
/* Check 'r_attr_tot' otherwise we don't know if any values were set.