This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Oren Milman
Recipients Oren Milman
Date 2016-09-13.15:14:13
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1473779654.66.0.219445763591.issue28129@psf.upfronthosting.co.za>
In-reply-to
Content
------------ 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.
History
Date User Action Args
2016-09-13 15:14:14Oren Milmansetrecipients: + Oren Milman
2016-09-13 15:14:14Oren Milmansetmessageid: <1473779654.66.0.219445763591.issue28129@psf.upfronthosting.co.za>
2016-09-13 15:14:14Oren Milmanlinkissue28129 messages
2016-09-13 15:14:14Oren Milmancreate