Repository navigation
Commit aee9046
gh-148891: prevent crash in HAMT caused by GC during traverse (GH-148928)
`_PyHamt_Assoc` allocates HAMT nodes, which can trigger GC. A weakref callback or finaliser fired during GC could re-enter `contextvar_set`, replacing `ctx->ctx_vars` via `Py_SETREF` and freeing the old HAMT while `_PyHamt_Assoc` was still traversing it, causing a use-after-free.
Hold a strong reference to `ctx->ctx_vars` during the `_PyHamt_Assoc` call, so that a re-entrant free cannot affect the HAMT being traversed.
(cherry picked from commit 1798d4f)
Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com>
1 parent ac1d49f commit aee9046
2 files changed
Lines changed: 11 additions & 1 deletion
File tree
- Misc/NEWS.d/next/Core_and_Builtins
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
| 863 | + | |
| 864 | + | |
| 865 | + | |
| 866 | + | |
863 | 867 | | |
864 | | - | |
| 868 | + | |
| 869 | + | |
865 | 870 | | |
866 | 871 | | |
867 | 872 | | |
| |||
888 | 893 | | |
889 | 894 | | |
890 | 895 | | |
| 896 | + | |
| 897 | + | |
891 | 898 | | |
| 899 | + | |
892 | 900 | | |
| 901 | + | |
893 | 902 | | |
894 | 903 | | |
895 | 904 | | |
| |||
0 commit comments