]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-106168: Check allocated instead of size index bounds in PyList_SET_ITEM() (#111480)
authorscoder <stefan_ml@behnel.de>
Mon, 30 Oct 2023 11:24:21 +0000 (12:24 +0100)
committerGitHub <noreply@github.com>
Mon, 30 Oct 2023 11:24:21 +0000 (12:24 +0100)
Check the index bound assertions in PyList_SET_ITEM() against [0:allocated] instead of [0:size] to re-allow valid use cases that assign within the allocated area.

Include/cpython/listobject.h

index 661610548733fd141d492f6d8084e3fc459d253c..c4d9052a09ef42268128ac7ce1f5dee36117b5de 100644 (file)
@@ -39,7 +39,7 @@ static inline void
 PyList_SET_ITEM(PyObject *op, Py_ssize_t index, PyObject *value) {
     PyListObject *list = _PyList_CAST(op);
     assert(0 <= index);
-    assert(index < Py_SIZE(list));
+    assert(index < list->allocated);
     list->ob_item[index] = value;
 }
 #define PyList_SET_ITEM(op, index, value) \