New submission from Oren Milman:

------------ current state ------------
In Modules\_ctypes\_ctypes.c, there are six functions with assertions that 
might fail:
    1. CDataType_from_buffer
    2. CDataType_from_buffer_copy
    3. PyCPointerType_set_type
    4. PyCPointerType_from_param
    5. PyCSimpleType_from_param
    6. _validate_paramflags
The following is true for each of these functions:
    - It assumes its first argument is a subclass (or an instance of a 
subclass) of some abstract ctype, which means it (the first argument) has a 
storage dict.
    - Thus, it asserts its first argument has a storage dict.
    - However, its first argument might be some abstract ctype (and not a 
subclass (or an instance of a subclass) of that abstract ctype), in which case 
the assertion fails.

In Modules\_ctypes\cfield.c, there are two functions with assertions that might 
fail:
    1. PyCField_set
    2. PyCField_get
These functions are the C implementations of the __set__ and __get__ functions 
(respectively) of the CFeild type. Each of them asserts its instance argument 
is a CDataObject, which might not be true.


------------ proposed changes ------------
Replace each of these assertions with an if statement that raises an exception 
in case of an invalid argument.


------------ diff ------------
The proposed patches diff file is attached.


------------ tests ------------
I wrote an ugly script to verify the assertion failures on CPython without my 
patches, and to test the patches on CPython with my patches. The script is 
attached, but it would probably fail on a non-Windows machine.

I built the patched CPython for x86, and played with it a little. Everything 
seemed to work as usual.

In addition, I ran 'python_d.exe -m test -j3' (on my 64-bit Windows 10) with 
and without the patches, and got quite the same output.
The outputs of both runs are attached.

----------
components: ctypes
files: testBugsOrPatches.py
messages: 276288
nosy: Oren Milman
priority: normal
severity: normal
status: open
title: assertion failures in ctypes
type: crash
versions: Python 3.7
Added file: http://bugs.python.org/file44636/testBugsOrPatches.py

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28129>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to