Message381475
PyType_GetModule() may return wrong or unexpected result when a type has
the feature flag Py_TPFLAGS_BASETYPE. The base type flag permits subclassing of an extension class. The function will return NULL when a type is subclasses in Python space or a different module object when the type is subclasses and initialized in a differen C extension module.
All subclassable types must use _PyType_GetModuleByDef() to safely access module and module state struct. It's easy to miss the problem. I missed it when I ported some of my code to heap types and multiphase init.
I propose to either a guard to PyType_GetModule() to prevent misuse of the function or to add a variant of the function that prevents misuse. |
|
Date |
User |
Action |
Args |
2020-11-20 10:28:14 | christian.heimes | set | recipients:
+ christian.heimes, vstinner, petr.viktorin, corona10 |
2020-11-20 10:28:13 | christian.heimes | set | messageid: <1605868093.25.0.0769747248067.issue42418@roundup.psfhosted.org> |
2020-11-20 10:28:13 | christian.heimes | link | issue42418 messages |
2020-11-20 10:28:13 | christian.heimes | create | |
|