gh-128212: Fix race in _PyUnicode_CheckConsistency (GH-128367)

There was a data race on the utf8 field between `PyUnicode_SET_UTF8` and
`_PyUnicode_CheckConsistency`. Use the `_PyUnicode_UTF8()` accessor,
which uses an atomic load internally, to avoid the data race.
This commit is contained in:
Sam Gross 2025-01-02 14:02:54 -05:00 committed by GitHub
parent c9356feef2
commit 8eebe4e6d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -688,7 +688,7 @@ _PyUnicode_CheckConsistency(PyObject *op, int check_content)
|| kind == PyUnicode_2BYTE_KIND
|| kind == PyUnicode_4BYTE_KIND);
CHECK(ascii->state.ascii == 0);
CHECK(compact->utf8 != data);
CHECK(_PyUnicode_UTF8(op) != data);
}
else {
PyUnicodeObject *unicode = _PyUnicodeObject_CAST(op);