Skip to content

Use a critical section to protect getlist() - #9853

Open
lazerg wants to merge 1 commit into
python-pillow:mainfrom
lazerg:fix/issue-9852-getlist-critical-section
Open

Use a critical section to protect getlist()#9853
lazerg wants to merge 1 commit into
python-pillow:mainfrom
lazerg:fix/issue-9852-getlist-critical-section

Conversation

@lazerg

@lazerg lazerg commented Aug 5, 2026

Copy link
Copy Markdown

getlist() reads the sequence length once, then walks the list with PySequence_Fast_GET_ITEM, which does no bounds checking and no locking. On a free-threaded build, another thread shrinking the list during the walk makes the remaining reads go past the end of the storage, so Image.point() segfaults. Wrapping the walk in a critical section on the argument keeps the length valid for the duration, the same approach used for FontObject in #9498.

Fixes #9852.

@radarhere radarhere added the Free-threading PEP 703 support label Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Free-threading PEP 703 support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Free-threaded: Image.point(list) crashes if another thread mutates the list (getlist / PySequence_Fast, stale size)

2 participants