[3.13] gh-143635: Fix crash in ga_repr_items_list (GH-143670) (#143852)

(cherry picked from commit bdba5f0db2)
This commit is contained in:
sobolevn 2026-01-15 18:27:31 +03:00 committed by GitHub
parent 149ecbb9a9
commit aa5ad50597
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 57 additions and 1 deletions

View file

@ -133,10 +133,15 @@ ga_repr_items_list(_PyUnicodeWriter *writer, PyObject *p)
return -1;
}
}
PyObject *item = PyList_GET_ITEM(p, i);
PyObject *item = PyList_GetItemRef(p, i);
if (item == NULL) {
return -1; // list can be mutated in a callback
}
if (ga_repr_item(writer, item) < 0) {
Py_DECREF(item);
return -1;
}
Py_DECREF(item);
}
if (_PyUnicodeWriter_WriteASCIIString(writer, "]", 1) < 0) {