Skip to content

Commit

Permalink
pythongh-128212: Fix race in _PyUnicode_CheckConsistency (pythonGH-…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
colesbury authored Jan 2, 2025
1 parent c9356fe commit 8eebe4e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 8eebe4e

Please sign in to comment.