[Python-checkins] GH-101696: invalidate type version tag in `_PyStaticType_Dealloc` (#101697)

kumaraditya303 webhook-mailer at python.org
Wed Feb 8 13:02:24 EST 2023


https://github.com/python/cpython/commit/d9de0792482d2ded364b0c7d2867b97a5da41b12
commit: d9de0792482d2ded364b0c7d2867b97a5da41b12
branch: main
author: Kumar Aditya <59607654+kumaraditya303 at users.noreply.github.com>
committer: kumaraditya303 <59607654+kumaraditya303 at users.noreply.github.com>
date: 2023-02-08T23:32:15+05:30
summary:

GH-101696: invalidate type version tag in `_PyStaticType_Dealloc` (#101697)

files:
A Misc/NEWS.d/next/Core and Builtins/2023-02-08-17-13-31.gh-issue-101696.seJhTt.rst
M Objects/typeobject.c

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 000000000000..ff2bbb4b5642
--- /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 59e0bf2995ba..bf6ccdb77a90 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -4469,6 +4469,8 @@ _PyStaticType_Dealloc(PyTypeObject *type)
     }
 
     type->tp_flags &= ~Py_TPFLAGS_READY;
+    type->tp_flags &= ~Py_TPFLAGS_VALID_VERSION_TAG;
+    type->tp_version_tag = 0;
 
     if (type->tp_flags & _Py_TPFLAGS_STATIC_BUILTIN) {
         _PyStaticType_ClearWeakRefs(type);



More information about the Python-checkins mailing list