It is possible to manually create an instance of private CField type which is used by ctypes to represent fields of Structure and Union types. This instance will be uninitialized because it's normally initialized when instances of Structure/Union are created, so calling its methods may crash the interpreter:
fromctypesimport*classS(Structure):
_fields_= [('x', c_int)]
CField=type(S.x)
f=CField()
repr(f) # Crash here
Is this issue worth fixing?
If so, is the correct way to set tp_new slot to NULL and fix the internal callers so that users wouldn't be able to create CField instances?
Activity
izbyshev commented on Sep 15, 2018
It is possible to manually create an instance of private CField type which is used by ctypes to represent fields of Structure and Union types. This instance will be uninitialized because it's normally initialized when instances of Structure/Union are created, so calling its methods may crash the interpreter:
Is this issue worth fixing?
If so, is the correct way to set tp_new slot to NULL and fix the internal callers so that users wouldn't be able to create CField instances?
serhiy-storchaka commented on Jul 13, 2019
Definitely yes.
I think yes.
Do you mind to create a PR?
shihai1991 commented on Jul 18, 2019
I have try to cancel this PyCField_new function, but i am not sure I haven't break the code structure.
shihai1991 commented on Aug 3, 2019
ping
gh-78878: Fix crash when creating an instance of `_ctypes.CField` (#1…
pythongh-78878: Fix crash when creating an instance of `_ctypes.CFiel…
gh-78878: Fix crash when creating an instance of `_ctypes.CField` (GH…
Merged main into regmachine branch (#50)