-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-46615: Don't crash when set operations mutate the sets #31120
Conversation
Checked for refleaks:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the right approach to me, but Raymond is much more familiar with this code. Added a comment about something that confused me in the new tests.
It's unclear to me why this doesn't crash with the added test cases: Lines 905 to 908 in 96b344c
|
None of these ever "crashed" on my box (Windows). Instead they weirded out silently in various ways (seemingly infinite loops, or the process just stopped without an error exit code). Just about anything can happen when mucking with freed memory - including no visible symptoms at all. Try running in a mode that checks runtime memory use (like valgrind)? |
Aha: set_add_entry already does |
def __eq__(self, other): | ||
if not enabled: | ||
return False | ||
if randrange(20) == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be better to use something like a counter, so that these tests behave consistently. The current behavior might make the test pass or fail inconsistently depending on what the RNG produces.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally okay with randomized tests, though I know others might feel differently. The test should pass for anything the RNG can give, and I'm personally more made more confident in code tested in millions of random situations, which ideally hit all of the corner cases I couldn't think of.
Co-authored-by: Jelle Zijlstra <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Thanks @sweeneyde for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10. |
Thanks @sweeneyde for the PR 🌮🎉.. I'm working now to backport this PR to: 3.9. |
Sorry, @sweeneyde, I could not cleanly backport this to |
GH-31284 is a backport of this pull request to the 3.10 branch. |
…31120) Ensure strong references are acquired whenever using `set_next()`. Added randomized test cases for `__eq__` methods that sometimes mutate sets when called. (cherry picked from commit 4a66615) Co-authored-by: Dennis Sweeney <[email protected]>
Ensure strong references are acquired whenever using `set_next()`. Added randomized test cases for `__eq__` methods that sometimes mutate sets when called. (cherry picked from commit 4a66615) Co-authored-by: Dennis Sweeney <[email protected]>
GH-31312 is a backport of this pull request to the 3.9 branch. |
…31120) (pythonGH-31312) Ensure strong references are acquired whenever using `set_next()`. Added randomized test cases for `__eq__` methods that sometimes mutate sets when called. (cherry picked from commit 4a66615)
Users of
set_next
should callPy_INCREF
on the resulting set keys to avoid use-after-free.https://bugs.python.org/issue46615