]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-128212: Fix race in `_PyUnicode_CheckConsistency` (GH-128367)
authorSam Gross <colesbury@gmail.com>
Thu, 2 Jan 2025 19:02:54 +0000 (14:02 -0500)
committerGitHub <noreply@github.com>
Thu, 2 Jan 2025 19:02:54 +0000 (14:02 -0500)
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

index 1aab9cf37768a89e5cac8f81618dbc1bf553f53c..9f0a4d4785eda6c78d10d74189424c8559ce9724 100644 (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);