Repository navigation
Crash on deallocator of type 'time.struct_time' during finalizing for free-threaded Python #122527
Copy link
Copy link
Closed
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-free-threadingtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Description
Activity
- addedtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
on Jul 31, 2024 Thanks for the report!
Confirmed on current main.- added3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes
on Jul 31, 2024 Bisected to:
(oops)
The problem is in
structseq_dealloc, theREAL_SIZE()call fails:Lines 116 to 131 in 8844197
static void structseq_dealloc(PyStructSequence *obj) { Py_ssize_t i, size; PyObject_GC_UnTrack(obj); PyTypeObject *tp = Py_TYPE(obj); size = REAL_SIZE(obj); for (i = 0; i < size; ++i) { Py_XDECREF(obj->ob_item[i]); } PyObject_GC_Del(obj); if (_PyType_HasFeature(tp, Py_TPFLAGS_HEAPTYPE)) { Py_DECREF(tp); } } REAL_SIZEis a macro that expands to:PyDict_GetItemWithError(_PyType_GetDict(Py_TYPE(self)), _Py_ID(n_fields))The GC is clearing the type's dictionary (i.e.,
_PyType_GetDict) before thestructseqinstances is freed, so theREAL_SIZEcall fails. We're also not handling that failure, which leads to a crash.The default build works because the GC happens to free the
structseqinstance first before callingtp_clear()on the type's dictionary, but I don't think the GC guarantees any ordering oftp_clear()calls.Reacted by Xuehai PanYou can trigger a similar crash in the default build with some weirder code:
import time obj = time.struct_time(range(1, 10)) type(obj).obj = obj- added a commit that references this issue
on Sep 2, 2024 - added a commit that references this issue
on Sep 6, 2024
Metadata
Metadata
Assignees
Labels
3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixestopic-free-threadingtype-crashA hard crash of the interpreter, possibly with a core dumpA hard crash of the interpreter, possibly with a core dump
Crash report
What happened?
A simple standalone file:
If I remove the assignment for
obj, the program can exit successfully.CPython versions tested on:
CPython main branch, CPython 3.13t, CPython 3.14t
Operating systems tested on:
Linux, macOS
Output from running 'python -VV' on the command line:
Python 3.14.0a0 experimental free-threading build (heads/main:bd3d31f, Aug 1 2024, 01:22:33) [Clang 15.0.0 (clang-1500.3.9.4)]
Linked PRs
PyStructSequence#122577PyStructSequence(GH-122577) #122625PyStructSequence(GH-122577) #122626