mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-117657: Fix data race in compare_unicode_unicode_threadsafe
(gh-131746)
We can't safely check the type of the found key until we incref it or if we know that it's immortal.
This commit is contained in:
parent
ac12de2e6a
commit
5abff6960b
1 changed files with 3 additions and 1 deletions
|
@ -1412,18 +1412,20 @@ compare_unicode_unicode_threadsafe(PyDictObject *mp, PyDictKeysObject *dk,
|
||||||
{
|
{
|
||||||
PyDictUnicodeEntry *ep = &((PyDictUnicodeEntry *)ep0)[ix];
|
PyDictUnicodeEntry *ep = &((PyDictUnicodeEntry *)ep0)[ix];
|
||||||
PyObject *startkey = _Py_atomic_load_ptr_relaxed(&ep->me_key);
|
PyObject *startkey = _Py_atomic_load_ptr_relaxed(&ep->me_key);
|
||||||
assert(startkey == NULL || PyUnicode_CheckExact(startkey));
|
|
||||||
if (startkey == key) {
|
if (startkey == key) {
|
||||||
|
assert(PyUnicode_CheckExact(startkey));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
if (startkey != NULL) {
|
if (startkey != NULL) {
|
||||||
if (_Py_IsImmortal(startkey)) {
|
if (_Py_IsImmortal(startkey)) {
|
||||||
|
assert(PyUnicode_CheckExact(startkey));
|
||||||
return unicode_get_hash(startkey) == hash && unicode_eq(startkey, key);
|
return unicode_get_hash(startkey) == hash && unicode_eq(startkey, key);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!_Py_TryIncrefCompare(&ep->me_key, startkey)) {
|
if (!_Py_TryIncrefCompare(&ep->me_key, startkey)) {
|
||||||
return DKIX_KEY_CHANGED;
|
return DKIX_KEY_CHANGED;
|
||||||
}
|
}
|
||||||
|
assert(PyUnicode_CheckExact(startkey));
|
||||||
if (unicode_get_hash(startkey) == hash && unicode_eq(startkey, key)) {
|
if (unicode_get_hash(startkey) == hash && unicode_eq(startkey, key)) {
|
||||||
Py_DECREF(startkey);
|
Py_DECREF(startkey);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue