]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-144295: Fix data race in dict method lookup and global load (gh-144312)
authorSam Gross <colesbury@gmail.com>
Fri, 30 Jan 2026 16:14:10 +0000 (11:14 -0500)
committerGitHub <noreply@github.com>
Fri, 30 Jan 2026 16:14:10 +0000 (11:14 -0500)
commite666a01ef42939f77f4c22ca47a610df5ef8b7ab
treed3607eedf3f0ecbde7406b86d8749bc2a7915639
parent1dc12b2883c89045469f3c401157d4df13f535f0
gh-144295: Fix data race in dict method lookup and global load (gh-144312)

In `_PyDict_GetMethodStackRef`, only use the fast-path unicode lookup
when the dict is owned by the current thread or already marked as shared.
This prevents a race between the lookup and concurrent dict resizes,
which may free the PyDictKeysObject (i.e., it ensures that the resize
uses QSBR).

Address a similar issue in `_Py_dict_lookup_threadsafe_stackref` by
calling `ensure_shared_on_read()`.
Lib/test/test_free_threading/test_dict.py
Objects/dictobject.c