René's URL Explorer Experiment


Title: Use-after-free in `Context.__eq__` via re-entrant `ContextVar.set` · Issue #142829 · python/cpython · GitHub

Open Graph Title: Use-after-free in `Context.__eq__` via re-entrant `ContextVar.set` · Issue #142829 · python/cpython

X Title: Use-after-free in `Context.__eq__` via re-entrant `ContextVar.set` · Issue #142829 · python/cpython

Description: What happened? Re-entrant ContextVar.set during _PyHamt_Eq lets Context.__eq__ replace a context while hamt_iterator_next still walks the old HAMT nodes, leaving the iterator with freed storage and producing a use-after-free when compari...

Open Graph Description: What happened? Re-entrant ContextVar.set during _PyHamt_Eq lets Context.__eq__ replace a context while hamt_iterator_next still walks the old HAMT nodes, leaving the iterator with freed storage and...

X Description: What happened? Re-entrant ContextVar.set during _PyHamt_Eq lets Context.__eq__ replace a context while hamt_iterator_next still walks the old HAMT nodes, leaving the iterator with freed storage and...

Opengraph URL: https://github.com/python/cpython/issues/142829

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Use-after-free in `Context.__eq__` via re-entrant `ContextVar.set`","articleBody":"### What happened?\n\nRe-entrant `ContextVar.set` during `_PyHamt_Eq` lets `Context.__eq__` replace a context while `hamt_iterator_next` still walks the old HAMT nodes, leaving the iterator with freed storage and producing a use-after-free when comparing two `Context` instances.\n\n**Proof of Concept:**\n```python\nimport contextvars\n\nvar = contextvars.ContextVar(\"v\")\nctx1 = contextvars.Context()\nctx2 = contextvars.Context()\n\n\nclass Boom:\n    def __eq__(self, other):\n        ctx1.run(lambda: var.set(object()))\n        return True\n\n\nctx1.run(var.set, Boom())\nctx2.run(var.set, object())\nctx1 == ctx2\n```\n\n\n**Affected Versions:**\n\u003cdetails>\n\n| Python Version | Status | Exit Code |\n|---|---|---|\n| `Python 3.9.24+ (heads/3.9:111bbc15b26, Oct 27 2025, 21:34:13) ` | ASAN | 1 |\n| `Python 3.10.19+ (heads/3.10:014261980b1, Oct 27 2025, 21:19:00) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.11.14+ (heads/3.11:88f3f5b5f11, Oct 27 2025, 21:20:35) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.12.12+ (heads/3.12:8cb2092bd8c, Oct 27 2025, 21:27:07) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.13.9+ (heads/3.13:9c8eade20c6, Oct 27 2025, 21:28:49) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.14.0+ (heads/3.14:2e216728038, Oct 27 2025, 21:30:55) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n| `Python 3.15.0a1+ (heads/main:f5394c257ce, Oct 27 2025, 21:32:37) [Clang 18.1.3 (1ubuntu1)]` | ASAN | 1 |\n\n\u003c/details>\n\n**Vulnerable Code:**\n\u003cdetails>\n\n```c\nint\n_PyHamt_Eq(PyHamtObject *v, PyHamtObject *w)\n{\n    if (v == w) {\n        return 1;\n    }\n\n    if (v->h_count != w->h_count) {\n        return 0;\n    }\n\n    PyHamtIteratorState iter;\n    hamt_iter_t iter_res;\n    hamt_find_t find_res;\n    PyObject *v_key;\n    PyObject *v_val;\n    PyObject *w_val;\n\n    hamt_iterator_init(&iter, v->h_root);\n\n    do {\n        iter_res = hamt_iterator_next(&iter, &v_key, &v_val);\n        if (iter_res == I_ITEM) {\n            find_res = hamt_find(w, v_key, &w_val);\n            switch (find_res) {\n                case F_ERROR:\n                    return -1;\n\n                case F_NOT_FOUND:\n                    return 0;\n\n                case F_FOUND: {\n                    // Bug: Enter the __eq__ method which can tear down the HAMT we’re iterating\n                    int cmp = PyObject_RichCompareBool(v_val, w_val, Py_EQ);\n                    if (cmp \u003c 0) {\n                        return -1;\n                    }\n                    if (cmp == 0) {\n                        return 0;\n                    }\n                }\n            }\n        }\n    } while (iter_res != I_END);\n\n    return 1;\n}\n```\n\n\u003c/details>\n\n**Sanitizer Output:**\n\u003cdetails>\n\n```\n=================================================================\n==1348779==ERROR: AddressSanitizer: heap-use-after-free on address 0x5060000cff98 at pc 0x5b670b71e4b3 bp 0x7ffca41ad830 sp 0x7ffca41ad828\nREAD of size 8 at 0x5060000cff98 thread T0\n    #0 0x5b670b71e4b2 in _Py_TYPE /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/object.h:277:20\n    #1 0x5b670b71e4b2 in Py_IS_TYPE /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/object.h:302:12\n    #2 0x5b670b71e4b2 in hamt_iterator_next /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:2193:9\n    #3 0x5b670b71de0a in _PyHamt_Eq /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:2341:20\n    #4 0x5b670b6c8393 in context_tp_richcompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:565:15\n    #5 0x5b670b464817 in do_richcompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:1059:15\n    #6 0x5b670b464817 in PyObject_RichCompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:1108:21\n    #7 0x5b670b65e386 in _PyEval_EvalFrameDefault /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/generated_cases.c.h:4683:35\n    #8 0x5b670b6463bb in _PyEval_EvalFrame /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_ceval.h:121:16\n    #9 0x5b670b6463bb in _PyEval_Vector /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:2005:12\n    #10 0x5b670b6463bb in PyEval_EvalCode /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:888:21\n    #11 0x5b670b79d370 in run_eval_code_obj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1365:12\n    #12 0x5b670b79d370 in run_mod /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1459:19\n    #13 0x5b670b79743c in pyrun_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1293:15\n    #14 0x5b670b79743c in _PyRun_SimpleFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:521:13\n    #15 0x5b670b796b05 in _PyRun_AnyFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:81:15\n    #16 0x5b670b7fefe5 in pymain_run_file_obj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:410:15\n    #17 0x5b670b7fefe5 in pymain_run_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:429:15\n    #18 0x5b670b7fd99d in pymain_run_python /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:691:21\n    #19 0x5b670b7fd99d in Py_RunMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:772:5\n    #20 0x5b670b7fe451 in pymain_main /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:802:12\n    #21 0x5b670b7fe5c3 in Py_BytesMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:826:12\n    #22 0x779d3a22a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16\n    #23 0x779d3a22a28a in __libc_start_main csu/../csu/libc-start.c:360:3\n    #24 0x5b670b1ae104 in _start (/home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/python+0x1c7104) (BuildId: 5de9d2fcbcd44bfc1b0fe256566d49ad35ca1d56)\n\n0x5060000cff98 is located 24 bytes inside of 64-byte region [0x5060000cff80,0x5060000cffc0)\nfreed by thread T0 here:\n    #0 0x5b670b248cba in free (/home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/python+0x261cba) (BuildId: 5de9d2fcbcd44bfc1b0fe256566d49ad35ca1d56)\n    #1 0x5b670b46ace1 in _Py_Dealloc /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:3200:5\n    #2 0x5b670b71edad in Py_DECREF /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/refcount.h:420:9\n    #3 0x5b670b71edad in hamt_tp_clear /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:2606:5\n    #4 0x5b670b71edad in hamt_tp_dealloc /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:2636:11\n    #5 0x5b670b46ace1 in _Py_Dealloc /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:3200:5\n    #6 0x5b670b6c71b6 in Py_DECREF /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/refcount.h:420:9\n    #7 0x5b670b6c71b6 in contextvar_set /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:801:5\n    #8 0x5b670b6c71b6 in PyContextVar_Set /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:367:9\n    #9 0x5b670b37ea3b in _PyObject_VectorcallTstate /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_call.h:169:11\n    #10 0x5b670b37ea3b in PyObject_Vectorcall /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/call.c:327:12\n    #11 0x5b670b665837 in _PyEval_EvalFrameDefault /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/generated_cases.c.h:1620:35\n    #12 0x5b670b646a14 in _PyEval_EvalFrame /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_ceval.h:121:16\n    #13 0x5b670b646a14 in _PyEval_Vector /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:2005:12\n    #14 0x5b670b6c9b13 in _PyObject_VectorcallTstate /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_call.h:169:11\n    #15 0x5b670b6c9b13 in context_run /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:728:29\n    #16 0x5b670b37ea3b in _PyObject_VectorcallTstate /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_call.h:169:11\n    #17 0x5b670b37ea3b in PyObject_Vectorcall /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/call.c:327:12\n    #18 0x5b670b665837 in _PyEval_EvalFrameDefault /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/generated_cases.c.h:1620:35\n    #19 0x5b670b646a14 in _PyEval_EvalFrame /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_ceval.h:121:16\n    #20 0x5b670b646a14 in _PyEval_Vector /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:2005:12\n    #21 0x5b670b4c4488 in _PyObject_VectorcallTstate /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_call.h:169:11\n    #22 0x5b670b4c4488 in vectorcall_unbound /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/typeobject.c:3034:12\n    #23 0x5b670b4c4488 in maybe_call_special_one_arg /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/typeobject.c:3176:15\n    #24 0x5b670b4effc0 in _PyObject_MaybeCallSpecialOneArg /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/typeobject.c:3191:12\n    #25 0x5b670b4effc0 in slot_tp_richcompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/typeobject.c:10736:21\n    #26 0x5b670b464817 in do_richcompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:1059:15\n    #27 0x5b670b464817 in PyObject_RichCompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:1108:21\n    #28 0x5b670b464397 in PyObject_RichCompareBool /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:1130:11\n    #29 0x5b670b71ddda in _PyHamt_Eq /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:2352:31\n    #30 0x5b670b6c8393 in context_tp_richcompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:565:15\n    #31 0x5b670b464817 in do_richcompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:1059:15\n    #32 0x5b670b464817 in PyObject_RichCompare /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/object.c:1108:21\n    #33 0x5b670b65e386 in _PyEval_EvalFrameDefault /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/generated_cases.c.h:4683:35\n    #34 0x5b670b6463bb in _PyEval_EvalFrame /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_ceval.h:121:16\n    #35 0x5b670b6463bb in _PyEval_Vector /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:2005:12\n    #36 0x5b670b6463bb in PyEval_EvalCode /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:888:21\n    #37 0x5b670b79d370 in run_eval_code_obj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1365:12\n    #38 0x5b670b79d370 in run_mod /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1459:19\n    #39 0x5b670b79743c in pyrun_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1293:15\n    #40 0x5b670b79743c in _PyRun_SimpleFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:521:13\n    #41 0x5b670b796b05 in _PyRun_AnyFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:81:15\n    #42 0x5b670b7fefe5 in pymain_run_file_obj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:410:15\n    #43 0x5b670b7fefe5 in pymain_run_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:429:15\n    #44 0x5b670b7fd99d in pymain_run_python /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:691:21\n    #45 0x5b670b7fd99d in Py_RunMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:772:5\n    #46 0x5b670b7fe451 in pymain_main /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:802:12\n    #47 0x5b670b7fe5c3 in Py_BytesMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:826:12\n    #48 0x779d3a22a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16\n    #49 0x779d3a22a28a in __libc_start_main csu/../csu/libc-start.c:360:3\n\npreviously allocated by thread T0 here:\n    #0 0x5b670b248f53 in malloc (/home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/python+0x261f53) (BuildId: 5de9d2fcbcd44bfc1b0fe256566d49ad35ca1d56)\n    #1 0x5b670b7040f8 in _PyObject_MallocWithType /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_object_alloc.h:46:17\n    #2 0x5b670b7040f8 in gc_alloc /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/gc.c:2343:17\n    #3 0x5b670b7040f8 in _PyObject_GC_NewVar /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/gc.c:2385:25\n    #4 0x5b670b71fbda in hamt_node_bitmap_new /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:508:12\n    #5 0x5b670b71fbda in hamt_node_bitmap_assoc /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:874:38\n    #6 0x5b670b719f91 in _PyHamt_Assoc /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/hamt.c:2222:16\n    #7 0x5b670b6c7140 in contextvar_set /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:795:30\n    #8 0x5b670b6c7140 in PyContextVar_Set /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:367:9\n    #9 0x5b670b6c9b13 in _PyObject_VectorcallTstate /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_call.h:169:11\n    #10 0x5b670b6c9b13 in context_run /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/context.c:728:29\n    #11 0x5b670b37ea3b in _PyObject_VectorcallTstate /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_call.h:169:11\n    #12 0x5b670b37ea3b in PyObject_Vectorcall /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Objects/call.c:327:12\n    #13 0x5b670b665837 in _PyEval_EvalFrameDefault /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/generated_cases.c.h:1620:35\n    #14 0x5b670b6463bb in _PyEval_EvalFrame /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/internal/pycore_ceval.h:121:16\n    #15 0x5b670b6463bb in _PyEval_Vector /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:2005:12\n    #16 0x5b670b6463bb in PyEval_EvalCode /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/ceval.c:888:21\n    #17 0x5b670b79d370 in run_eval_code_obj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1365:12\n    #18 0x5b670b79d370 in run_mod /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1459:19\n    #19 0x5b670b79743c in pyrun_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:1293:15\n    #20 0x5b670b79743c in _PyRun_SimpleFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:521:13\n    #21 0x5b670b796b05 in _PyRun_AnyFileObject /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Python/pythonrun.c:81:15\n    #22 0x5b670b7fefe5 in pymain_run_file_obj /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:410:15\n    #23 0x5b670b7fefe5 in pymain_run_file /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:429:15\n    #24 0x5b670b7fd99d in pymain_run_python /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:691:21\n    #25 0x5b670b7fd99d in Py_RunMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:772:5\n    #26 0x5b670b7fe451 in pymain_main /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:802:12\n    #27 0x5b670b7fe5c3 in Py_BytesMain /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/Modules/main.c:826:12\n    #28 0x779d3a22a1c9 in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16\n    #29 0x779d3a22a28a in __libc_start_main csu/../csu/libc-start.c:360:3\n    #30 0x5b670b1ae104 in _start (/home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/python+0x1c7104) (BuildId: 5de9d2fcbcd44bfc1b0fe256566d49ad35ca1d56)\n\nSUMMARY: AddressSanitizer: heap-use-after-free /home/jackfromeast/Desktop/entropy/tasks/reproducexx/targets/cpython-main/./Include/object.h:277:20 in _Py_TYPE\nShadow bytes around the buggy address:\n  0x5060000cfd00: 00 00 07 fa fa fa fa fa 00 00 00 00 00 00 00 00\n  0x5060000cfd80: fa fa fa fa 00 00 00 00 00 00 07 fa fa fa fa fa\n  0x5060000cfe00: 00 00 00 00 00 00 00 00 fa fa fa fa 00 00 00 00\n  0x5060000cfe80: 00 00 00 00 fa fa fa fa fd fd fd fd fd fd fd fa\n  0x5060000cff00: fa fa fa fa fd fd fd fd fd fd fd fd fa fa fa fa\n=>0x5060000cff80: fd fd fd[fd]fd fd fd fd fa fa fa fa fd fd fd fd\n  0x5060000d0000: fd fd fd fa fa fa fa fa fd fd fd fd fd fd fd fd\n  0x5060000d0080: fa fa fa fa 00 00 00 00 00 00 00 00 fa fa fa fa\n  0x5060000d0100: 00 00 00 00 00 00 00 fa fa fa fa fa fd fd fd fd\n  0x5060000d0180: fd fd fd fd fa fa fa fa 00 00 00 00 00 00 00 00\n  0x5060000d0200: fa fa fa fa 00 00 00 00 00 00 00 fa fa fa fa fa\nShadow byte legend (one shadow byte represents 8 application bytes):\n  Addressable:           00\n  Partially addressable: 01 02 03 04 05 06 07 \n  Heap left redzone:       fa\n  Freed heap region:       fd\n  Stack left redzone:      f1\n  Stack mid redzone:       f2\n  Stack right redzone:     f3\n  Stack after return:      f5\n  Stack use after scope:   f8\n  Global redzone:          f9\n  Global init order:       f6\n  Poisoned by user:        f7\n  Container overflow:      fc\n  Array cookie:            ac\n  Intra object redzone:    bb\n  ASan internal:           fe\n  Left alloca redzone:     ca\n  Right alloca redzone:    cb\n==1348779==ABORTING\n```\n\n\u003c/details>\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-142905\n* gh-143627\n* gh-143871\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/jackfromeast","@type":"Person","name":"jackfromeast"},"datePublished":"2025-12-16T14:49:29Z","url":"https://github.com/python/cpython/issues/142829"}

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:edb69446-ed69-c727-a273-ba5fee5b126c
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id89DA:24645:17CDCFA:1F60273:6B020853
html-safe-nonce317274afa0e5608f564df4e1abe88a4e59057d0ba18fef207f5f9af73f1c6763
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4OURBOjI0NjQ1OjE3Q0RDRkE6MUY2MDI3Mzo2QjAyMDg1MyIsInZpc2l0b3JfaWQiOiIzMjQ2OTM4Mzg1NDEyMjgxMTYiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac30729a96e898d4c335407514f4fcee3b434ef5219874055692a3e2684e5bc8d6
hovercard-subject-tagissue:3735124237
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/142829/issue_layout
twitter:imagehttps://opengraph.githubassets.com/eabc7b9ab97cd32f69ede3cc68f6d582d109c11badbf583af17522bcf485bfa9/python/cpython/issues/142829
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/eabc7b9ab97cd32f69ede3cc68f6d582d109c11badbf583af17522bcf485bfa9/python/cpython/issues/142829
og:image:altWhat happened? Re-entrant ContextVar.set during _PyHamt_Eq lets Context.__eq__ replace a context while hamt_iterator_next still walks the old HAMT nodes, leaving the iterator with freed storage and...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernamejackfromeast
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark
react-app-nameissues

Links:

Skip to contenthttps://github.com/python/cpython/issues/142829#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F142829
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fissues%2F142829
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/issues/142829
Reloadhttps://github.com/python/cpython/issues/142829
Reloadhttps://github.com/python/cpython/issues/142829
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
https://github.com/python/cpython
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/142829
New issuehttps://github.com/login?return_to=https://github.com/python/cpython/issues/142829
Use-after-free in Context.__eq__ via re-entrant ContextVar.sethttps://github.com/python/cpython/issues/142829#top
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com/jackfromeast
jackfromeasthttps://github.com/jackfromeast
on Dec 16, 2025https://github.com/python/cpython/issues/142829#issue-3735124237
gh-142829: Fix use-after-free in Context.__eq__ via re-entrant ContextVar.set #142905https://github.com/python/cpython/pull/142905
[3.14] gh-142829: Fix use-after-free in Context.__eq__ via re-entrant ContextVar.set (GH-142905) #143627https://github.com/python/cpython/pull/143627
[3.13] gh-142829: Fix use-after-free in Context.__eq__ via re-entrant ContextVar.set (GH-142905) #143871https://github.com/python/cpython/pull/143871
aiskhttps://github.com/aisk
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
on Dec 16, 2025https://github.com/python/cpython/issues/142829#event-21595393733
abdoulrasheedhttps://github.com/abdoulrasheed
on Dec 17, 2025https://github.com/python/cpython/issues/142829#event-21625849137
pythongh-142829: Fix use-after-free in Context.__eq__ via re-entrant …https://github.com/abdoulrasheed/cpython/commit/4e7e015ed1634f85e6cfb75fdc28eace309749ab
pythongh-142829https://github.com/python/cpython/issues/142829
4e7e015https://github.com/abdoulrasheed/cpython/commit/4e7e015ed1634f85e6cfb75fdc28eace309749ab
pythongh-142829: Add test for __hash__ re-entrancy in Context comparisonhttps://github.com/abdoulrasheed/cpython/commit/c7e4a790ab722f52a29e1371e0c03abc49f90268
pythongh-142829https://github.com/python/cpython/issues/142829
c7e4a79https://github.com/abdoulrasheed/cpython/commit/c7e4a790ab722f52a29e1371e0c03abc49f90268
kumaraditya303https://github.com/kumaraditya303
on Jan 9, 2026https://github.com/python/cpython/issues/142829#event-21945845789
Merge branch 'main' into fix-pythongh-142829-context-uafhttps://github.com/abdoulrasheed/cpython/commit/8540de5ee0fec2879282a021e66060c45749a522
pythongh-142829https://github.com/python/cpython/issues/142829
8540de5https://github.com/abdoulrasheed/cpython/commit/8540de5ee0fec2879282a021e66060c45749a522
gh-142829: Fix use-after-free in `Context.__eq__` via re-entrant `Con…https://github.com/python/cpython/commit/a4086d7f89e5d388e4ffcdb13e4fba0255234286
gh-142829https://github.com/python/cpython/issues/142829
a4086d7https://github.com/python/cpython/commit/a4086d7f89e5d388e4ffcdb13e4fba0255234286
miss-islingtonhttps://github.com/miss-islington
on Jan 9, 2026https://github.com/python/cpython/issues/142829#event-21952828852
pythongh-142829: Fix use-after-free in `Context.__eq__` via re-entran…https://github.com/miss-islington/cpython/commit/579dafa7964dfd9e843bccef8e05f9ed7d5be5bd
pythongh-142829https://github.com/python/cpython/issues/142829
579dafahttps://github.com/miss-islington/cpython/commit/579dafa7964dfd9e843bccef8e05f9ed7d5be5bd
kumaraditya303https://github.com/kumaraditya303
on Jan 10, 2026https://github.com/python/cpython/issues/142829#event-21960647904
[3.14] gh-142829: Fix use-after-free in `Context.__eq__` via re-entra…https://github.com/python/cpython/commit/16efe851292d3168a65e259e19e2cc96d0635de6
gh-142829https://github.com/python/cpython/issues/142829
16efe85https://github.com/python/cpython/commit/16efe851292d3168a65e259e19e2cc96d0635de6
reidenonghttps://github.com/reidenong
on Jan 12, 2026https://github.com/python/cpython/issues/142829#event-21999448947
pythongh-142829: Fix use-after-free in `Context.__eq__` via re-entran…https://github.com/reidenong/cpython/commit/c2f5b939ab925d23a6788ffff81dbd7b2c180e11
pythongh-142829https://github.com/python/cpython/issues/142829
c2f5b93https://github.com/reidenong/cpython/commit/c2f5b939ab925d23a6788ffff81dbd7b2c180e11
serhiy-storchakahttps://github.com/serhiy-storchaka
on Jan 15, 2026https://github.com/python/cpython/issues/142829#event-22071533512
[3.13] pythongh-142829: Fix use-after-free in `Context.__eq__` via re…https://github.com/serhiy-storchaka/cpython/commit/ac7af341d0d8132fe3a9c3290d1d048b9dca9fbb
pythongh-142829https://github.com/python/cpython/issues/142829
ac7af34https://github.com/serhiy-storchaka/cpython/commit/ac7af341d0d8132fe3a9c3290d1d048b9dca9fbb
serhiy-storchakahttps://github.com/serhiy-storchaka
completedhttps://github.com/python/cpython/issues?q=is%3Aissue%20state%3Aclosed%20archived%3Afalse%20reason%3Acompleted
on Jan 15, 2026https://github.com/python/cpython/issues/142829#event-22071562787
serhiy-storchakahttps://github.com/serhiy-storchaka
on Jan 15, 2026https://github.com/python/cpython/issues/142829#event-22072065030
[3.13] gh-142829: Fix use-after-free in `Context.__eq__` via re-entra…https://github.com/python/cpython/commit/149ecbb9a9e6e58a60c83783412de2c8dc0c9db9
gh-142829https://github.com/python/cpython/issues/142829
149ecbbhttps://github.com/python/cpython/commit/149ecbb9a9e6e58a60c83783412de2c8dc0c9db9
thunder-codinghttps://github.com/thunder-coding
on Feb 15, 2026https://github.com/python/cpython/issues/142829#event-22797344975
pythongh-142829: Fix use-after-free in `Context.__eq__` via re-entran…https://github.com/thunder-coding/cpython/commit/49ee64a4316649e2aac30be1ffeab2eeb483896c
pythongh-142829https://github.com/python/cpython/issues/142829
49ee64ahttps://github.com/thunder-coding/cpython/commit/49ee64a4316649e2aac30be1ffeab2eeb483896c
Sign up for freehttps://github.com/signup?return_to=https://github.com/python/cpython/issues/142829
Sign in to commenthttps://github.com/login?return_to=https://github.com/python/cpython/issues/142829
interpreter-core(Objects, Python, Grammar, and Parser dirs)https://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22interpreter-core%22
type-crashA hard crash of the interpreter, possibly with a core dumphttps://github.com/python/cpython/issues?q=state%3Aopen%20label%3A%22type-crash%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.