Skip to content

gh-153981: Fix use after free bug itertools.count() - #153983

Open
johng wants to merge 4 commits into
python:mainfrom
johng:use-after-free-iter-tools
Open

johng wants to merge 4 commits into
python:mainfrom
johng:use-after-free-iter-tools

Conversation

@johng

@johng johng commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor

Obtain a reference to lz->long_cnt, lz->long_step
such that we don't hit a use after free.

@johng
johng requested a review from rhettinger as a code owner July 18, 2026 14:39
@johng johng changed the title gr-153981 Fix use after free bug itertools.count() gr-153981: Fix use after free bug itertools.count() Jul 18, 2026
@johng
johng force-pushed the use-after-free-iter-tools branch from 8623456 to 765d7d5 Compare July 18, 2026 14:40
Obtain a reference to lz->long_cnt, lz->long_step
such that we don't hit a use after free
@johng
johng force-pushed the use-after-free-iter-tools branch from 765d7d5 to 8580b6a Compare July 18, 2026 14:42
@johng johng changed the title gr-153981: Fix use after free bug itertools.count() gh-153981: Fix use after free bug itertools.count() Jul 18, 2026
@johng

johng commented Jul 18, 2026 •

Copy link
Copy Markdown
Contributor Author

This appears to add some very slight overhead to repr in slow mode, no impact to the likely more heavily used fast mode

Comment thread Modules/itertoolsmodule.c
Comment thread Misc/NEWS.d/next/Library/2026-07-18-14-47-52.gh-issue-153981.yZcmKQ.rst Outdated
@picnixz

picnixz commented Jul 24, 2026

Copy link
Copy Markdown
Member

Performances are not really inportant for __repr__. You usually don't print a count in a hot path.

johng and others added 2 commits July 25, 2026 21:59
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@johng
johng requested a review from picnixz July 25, 2026 21:01
@johng

johng commented Aug 15, 2026

Copy link
Copy Markdown
Contributor Author

@picnixz would you be able to kindly review again, thanks!

@johng

johng commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

@picnixz kindly pining for a re-review, thank you!

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may just seem dumb but since __repr__ is fairly used just for debugging, I don't think we really need to worry about performances; so why not just having everything in a critical section? would that work?

@johng

johng commented Oct 4, 2026

Copy link
Copy Markdown
Contributor Author

Would that not risk locking other threads executing more latency sensitive functions that are holding the lock?

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.

2 participants