From 8eebe4e6d02bb4ad3f1ca6c52624186903dce893 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Thu, 2 Jan 2025 14:02:54 -0500 Subject: [PATCH] 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. --- Objects/unicodeobject.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); -- 2.47.3