◐ Shell
clean mode source ↗

gh-118331: Fix a couple of issues when list allocation fails by mpage · Pull Request #130811 · python/cpython

Set the items pointer in the list object to NULL after the items array
is freed during list deallocation. Otherwise, we can end up with a list
object added to the free list that contains a pointer to an already-freed
items array.

@bedevere-app Bot mentioned this pull request

Mar 3, 2025
I think technically it's not escaping, because the only object that
can be decrefed if allocation fails is an exact list, which cannot
execute arbitrary code when it is destroyed. However, this seems less
intrusive than trying to special cases objects in the assert in `_Py_Dealloc`
that checks for non-null stackpointers and shouldn't matter for performance.

@mpage mpage changed the title gh-118331: Fix use after free in list objects gh-118331: Fix a couple of issues when list allocation fails

Mar 3, 2025

@mpage mpage marked this pull request as ready for review

March 4, 2025 00:03

colesbury

colesbury

corona10

@mpage

@mpage mpage mentioned this pull request

Mar 6, 2025