Skip to content

PyList_SetItem missing atomic store #129643

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
kumaraditya303 opened this issue Feb 4, 2025 · 1 comment
Closed

PyList_SetItem missing atomic store #129643

kumaraditya303 opened this issue Feb 4, 2025 · 1 comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error

Comments

@kumaraditya303
Copy link
Contributor

kumaraditya303 commented Feb 4, 2025

Bug report

PyList_SetItem currently uses Py_XSETREF to set the item and decref the old one, however the store is not atomic as such it can race with a concurrent read. The fix is to use a atomic store with release order to correctly set the new item and then decref the old object.

cc @colesbury @Yhg1s

Linked PRs

@kumaraditya303 kumaraditya303 added topic-free-threading type-bug An unexpected behavior, bug, or error labels Feb 4, 2025
@picnixz picnixz added the interpreter-core (Objects, Python, Grammar, and Parser dirs) label Feb 4, 2025
@colesbury
Copy link
Contributor

There is a similar issue in the function ins1:

items = self->ob_item;
for (i = n; --i >= where; )
items[i+1] = items[i];
items[where] = Py_NewRef(v);

kumaraditya303 added a commit to kumaraditya303/cpython that referenced this issue Feb 5, 2025
kumaraditya303 added a commit that referenced this issue Feb 5, 2025
sobolevn added a commit to sobolevn/cpython that referenced this issue Feb 5, 2025
sobolevn added a commit to sobolevn/cpython that referenced this issue Feb 6, 2025
sobolevn added a commit that referenced this issue Feb 6, 2025
@sobolevn sobolevn closed this as completed Feb 6, 2025
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Feb 7, 2025
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this issue Feb 7, 2025
cmaloney pushed a commit to cmaloney/cpython that referenced this issue Feb 8, 2025
cmaloney pushed a commit to cmaloney/cpython that referenced this issue Feb 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-free-threading type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants