gh-151633: avoid use-after-free in Counter.update#151634
Open
KowalskiThomas wants to merge 9 commits into
Open
gh-151633: avoid use-after-free in Counter.update#151634KowalskiThomas wants to merge 9 commits into
Counter.update#151634KowalskiThomas wants to merge 9 commits into
Conversation
eendebakpt
reviewed
Jun 18, 2026
eendebakpt
reviewed
Jul 7, 2026
Contributor
Author
|
Thanks for the review, I'll take a look ASAP. |
eendebakpt
reviewed
Jul 10, 2026
| int found; | ||
| int cs_err = 0; | ||
| PyObject *newval = NULL; | ||
| Py_BEGIN_CRITICAL_SECTION(mapping); |
Contributor
There was a problem hiding this comment.
The current PR looks good, but I think we can improve a bit more. The locking via the critical section now happens on each iteration, which seems a bit of a waste.
Can we place the critical section outside the while loop and then extract most (all?) of the code into a method _count_elements_dict_lock_held?
Contributor
Author
There was a problem hiding this comment.
I'll look into this as soon as possible, thanks for reporting.
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
Co-authored-by: Pieter Eendebak <pieter.eendebak@gmail.com>
192fc9f to
c34c4a2
Compare
Contributor
Author
|
Sorry in advance, I had to rebase on main (instead of merge) because Git wouldn't let me "merge unrelated histories"... Not sure what happened there... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #151633.
Counter.updatecan cause a use after free #151633