PyAPI: prevent indices below -1 being used by StructRNA.path_from_module

Disable this as RNA paths don't support Python-style negative indexing.

Ref !147255
This commit is contained in:
Campbell Barton
2025-10-15 07:59:23 +00:00
parent 365757ce7e
commit e809e6364d

View File

@@ -4016,6 +4016,7 @@ PyDoc_STRVAR(
" The incomplete path will be printed in the error message.\n");
static PyObject *pyrna_struct_path_from_module(BPy_StructRNA *self, PyObject *args)
{
const char *error_prefix = "path_from_module(...)";
const char *name = nullptr;
PropertyRNA *prop;
int index = -1;
@@ -4025,6 +4026,10 @@ static PyObject *pyrna_struct_path_from_module(BPy_StructRNA *self, PyObject *ar
if (!PyArg_ParseTuple(args, "|si:path_from_module", &name, &index)) {
return nullptr;
}
if (index < -1) {
PyErr_Format(PyExc_ValueError, "%s: indices below -1 are not supported", error_prefix);
return nullptr;
}
std::optional<std::string> path;
if (name) {