Skip to content

Commit

Permalink
pythongh-118561: Fix crash involving list.extend in free-threaded build
Browse files Browse the repository at this point in the history
The `list_preallocate_exact` function did not zero initialize array
contents. In the free-threaded build, this could expose uninitialized
memory to concurrent readers between the call to
`list_preallocate_exact` and the filling of the array contents with
items.
  • Loading branch information
colesbury committed May 7, 2024
1 parent 26bab42 commit d5ef753
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix race condition in free-threaded build where ``list.extend`` could expose
uninitialied memory to concurrent readers.
1 change: 1 addition & 0 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ list_preallocate_exact(PyListObject *self, Py_ssize_t size)
return -1;
}
items = array->ob_item;
memset(items, 0, size * sizeof(PyObject *));
#else
items = PyMem_New(PyObject*, size);
if (items == NULL) {
Expand Down

0 comments on commit d5ef753

Please sign in to comment.