From: Sam Gross Date: Thu, 2 Jan 2025 19:02:54 +0000 (-0500) Subject: gh-128212: Fix race in `_PyUnicode_CheckConsistency` (GH-128367) X-Git-Tag: v3.14.0a4~144 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8eebe4e6d02bb4ad3f1ca6c52624186903dce893;p=thirdparty%2FPython%2Fcpython.git 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. --- diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1aab9cf37768..9f0a4d4785ed 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -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);