-
-
Notifications
You must be signed in to change notification settings - Fork 35k
gh-154318: Guard C recursion when hashing nested tuples and frozendicts #154362
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -119,6 +119,18 @@ def check_one_exact(t, e32, e64): | |
| check_one_exact((0.5, (), (-2, 3, (4, 6))), 714642271, | ||
| -1845940830829704396) | ||
|
|
||
| @support.skip_if_huge_c_stack() | ||
| @support.skip_wasi_stack_overflow() | ||
| @support.skip_emscripten_stack_overflow() | ||
| def test_hash_deeply_nested(self): | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same comments apply here as well.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Applied all three to I also dropped the |
||
| # This should raise a RecursionError and not crash. | ||
| # See https://github.com/python/cpython/issues/154318. | ||
| t = () | ||
| for _ in range(support.exceeds_recursion_limit()): | ||
| t = (t,) | ||
| with self.assertRaisesRegex(RecursionError, "while hashing a tuple"): | ||
| hash(t) | ||
|
|
||
| # Various tests for hashing of tuples to check that we get few collisions. | ||
| # Does something only if RUN_ALL_HASH_TESTS is true. | ||
| # | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Fix a crash when hashing a deeply nested :class:`tuple` or :class:`frozendict`. | ||
| A :exc:`RecursionError` is now raised instead of overflowing the C stack. |
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.
tests with recursions must be properly guarded with skips.
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.
Done — added
@support.skip_if_huge_c_stack(),@support.skip_wasi_stack_overflow()and@support.skip_emscripten_stack_overflow()to both tests, matchingtest_repr_deep()a few hundred lines up in this same file.