Skip to content

gh-162822: fix bytearray construction from concurrently modified lists - #162839

Open
shashankrxj wants to merge 3 commits into
python:mainfrom
shashankrxj:gh-162822-bytearray-list-race
Open

shashankrxj wants to merge 3 commits into
python:mainfrom
shashankrxj:gh-162822-bytearray-list-race

Conversation

@shashankrxj

@shashankrxj shashankrxj commented Nov 29, 2026 •

Copy link
Copy Markdown

gh-162822: Free-threaded bytearray construction can crash when the source list is concurrently modified

In the free-threaded build, bytearray.init() accessed exact-list items without holding the list’s critical section. Another thread could replace and free an item while it was being converted.

The exact-list fast path now protects the source list and destination bytearray while reading the list and writing the result. Non-exact integers fall back to the iterator path after the critical sections are released.

Added free-threading tests for concurrent item replacement and list resizing.

@python-cla-bot

python-cla-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant