Skip to content

gh-158033: Keep the aiter sentinel alive during comparison - #158043

Open
lul-cas wants to merge 2 commits into
python:mainfrom
lul-cas:fix-issue-158033
Open

lul-cas wants to merge 2 commits into
python:mainfrom
lul-cas:fix-issue-158033

Conversation

@lul-cas

@lul-cas lul-cas commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

aiter(callable, sentinel) compared the sentinel through a borrowed reference. A reentrant __eq__ can exhaust the iterator and free that object while the comparison is still using it.

Hold a strong reference for the duration of PyObject_RichCompareBool.

Fixes #158033.

@ZeroIntensity

Copy link
Copy Markdown
Member

I think #157687 will fix this as well, but I suppose we could use this for 3.15 and below. cc @kumaraditya303

@picnixz

picnixz commented Sep 24, 2026

Copy link
Copy Markdown
Member

This would introduce contention in the FT build I think. We need some benchmarks to know if there are some real performance impacts. I believe we already have one open issue about a similar problem where we still did not have make the change just because of FT performance impacts

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.

uaf in aiter()

3 participants