From 3bb69e1862a94b9413a323a53fdc4740997bb623 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Mon, 30 Dec 2024 21:49:16 +0000 Subject: [PATCH] gh-128212: Fix race in `_PyUnicode_CheckConsistency` 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 1aab9cf37768a8..9f0a4d4785eda6 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);