Repository navigation
Commit 08500b0
authored
* gh-154318: Guard C recursion when hashing nested tuples and frozendicts
tuple_hash() and frozendict_hash() fold each contained object's hash into
an accumulator with PyObject_Hash() inside an unguarded loop. For a deeply
nested tuple or frozendict this recurses back into the same function once
per level and overflows the C stack (SIGSEGV / STATUS_STACK_OVERFLOW)
instead of raising RecursionError.
Wrap both loops in _Py_EnterRecursiveCall() / _Py_LeaveRecursiveCall(), as
the sibling comparison and repr paths already do. The guard is placed after
the cached-hash early return, so repeated hashing of an already-hashed
tuple is unaffected.
This also covers types.GenericAlias, whose ga_hash() hashes its __args__
tuple and so crashed through tuple_hash().
1 parent 5a17b2e commit 08500b0
5 files changed
Lines changed: 49 additions & 0 deletions
File tree
- Lib/test
- Misc/NEWS.d/next/Core_and_Builtins
- Objects
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1990 | 1990 | | |
1991 | 1991 | | |
1992 | 1992 | | |
| 1993 | + | |
| 1994 | + | |
| 1995 | + | |
| 1996 | + | |
| 1997 | + | |
| 1998 | + | |
| 1999 | + | |
| 2000 | + | |
| 2001 | + | |
| 2002 | + | |
| 2003 | + | |
| 2004 | + | |
| 2005 | + | |
| 2006 | + | |
| 2007 | + | |
1993 | 2008 | | |
1994 | 2009 | | |
1995 | 2010 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
126 | 138 | | |
127 | 139 | | |
128 | 140 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8474 | 8474 | | |
8475 | 8475 | | |
8476 | 8476 | | |
| 8477 | + | |
| 8478 | + | |
| 8479 | + | |
| 8480 | + | |
| 8481 | + | |
| 8482 | + | |
| 8483 | + | |
| 8484 | + | |
8477 | 8485 | | |
8478 | 8486 | | |
8479 | 8487 | | |
8480 | 8488 | | |
8481 | 8489 | | |
8482 | 8490 | | |
| 8491 | + | |
8483 | 8492 | | |
8484 | 8493 | | |
8485 | 8494 | | |
8486 | 8495 | | |
| 8496 | + | |
8487 | 8497 | | |
8488 | 8498 | | |
8489 | 8499 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
380 | 380 | | |
381 | 381 | | |
382 | 382 | | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
383 | 391 | | |
384 | 392 | | |
385 | 393 | | |
386 | 394 | | |
| 395 | + | |
387 | 396 | | |
388 | 397 | | |
389 | 398 | | |
390 | 399 | | |
391 | 400 | | |
392 | 401 | | |
| 402 | + | |
393 | 403 | | |
394 | 404 | | |
395 | 405 | | |
| |||
0 commit comments