From 5f83520e9a6708a1b8c3a942671fa17815e51e51 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Wed, 8 Feb 2023 23:32:15 +0530 Subject: [PATCH] [3.11] GH-101696: invalidate type version tag in `_PyStaticType_Dealloc` (GH-101697). (cherry picked from commit d9de0792482d2ded364b0c7d2867b97a5da41b12) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> --- .../2023-02-08-17-13-31.gh-issue-101696.seJhTt.rst | 1 + Objects/typeobject.c | 2 ++ 2 files changed, 3 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2023-02-08-17-13-31.gh-issue-101696.seJhTt.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-02-08-17-13-31.gh-issue-101696.seJhTt.rst b/Misc/NEWS.d/next/Core and Builtins/2023-02-08-17-13-31.gh-issue-101696.seJhTt.rst new file mode 100644 index 00000000000000..ff2bbb4b564252 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-02-08-17-13-31.gh-issue-101696.seJhTt.rst @@ -0,0 +1 @@ +Invalidate type version tag in ``_PyStaticType_Dealloc`` for static types, avoiding bug where a false cache hit could crash the interpreter. Patch by Kumar Aditya. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 9ee57105204e29..90c6425ffdfea5 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -4080,6 +4080,8 @@ _PyStaticType_Dealloc(PyTypeObject *type) } type->tp_flags &= ~Py_TPFLAGS_READY; + type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG; + type->tp_version_tag = 0; }