File tree Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Expand file tree Collapse file tree 3 files changed +21
-4
lines changed Original file line number Diff line number Diff line change @@ -77,5 +77,13 @@ def test_fom_buffer_copy_with_offset(self):
77
77
self .assertRaises (ValueError ,
78
78
(c_int * 1 ).from_buffer_copy , a , 16 * sizeof (c_int ))
79
79
80
+ def test_abstract (self ):
81
+ self .assertRaises (TypeError , Array .from_buffer , bytearray (10 ))
82
+ self .assertRaises (TypeError , Structure .from_buffer , bytearray (10 ))
83
+ self .assertRaises (TypeError , Union .from_buffer , bytearray (10 ))
84
+ self .assertRaises (TypeError , Array .from_buffer_copy , b"123" )
85
+ self .assertRaises (TypeError , Structure .from_buffer_copy , b"123" )
86
+ self .assertRaises (TypeError , Union .from_buffer_copy , b"123" )
87
+
80
88
if __name__ == '__main__' :
81
89
unittest .main ()
Original file line number Diff line number Diff line change @@ -63,6 +63,9 @@ Core and Builtins
63
63
Library
64
64
-------
65
65
66
+ - Issue #25659: In ctypes, prevent a crash calling the from_buffer() and
67
+ from_buffer_copy() methods on abstract classes like Array.
68
+
66
69
- Issue #28563: Fixed possible DoS and arbitrary code execution when handle
67
70
plural form selections in the gettext module. The expression parser now
68
71
supports exact syntax supported by GNU gettext.
Original file line number Diff line number Diff line change @@ -501,7 +501,10 @@ CDataType_from_buffer(PyObject *type, PyObject *args)
501
501
Py_ssize_t offset = 0 ;
502
502
PyObject * obj , * result ;
503
503
StgDictObject * dict = PyType_stgdict (type );
504
- assert (dict );
504
+ if (!dict ) {
505
+ PyErr_SetString (PyExc_TypeError , "abstract class" );
506
+ return NULL ;
507
+ }
505
508
506
509
if (!PyArg_ParseTuple (args ,
507
510
#if (PY_VERSION_HEX < 0x02050000 )
@@ -557,13 +560,16 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args)
557
560
Py_ssize_t offset = 0 ;
558
561
PyObject * obj , * result ;
559
562
StgDictObject * dict = PyType_stgdict (type );
560
- assert (dict );
563
+ if (!dict ) {
564
+ PyErr_SetString (PyExc_TypeError , "abstract class" );
565
+ return NULL ;
566
+ }
561
567
562
568
if (!PyArg_ParseTuple (args ,
563
569
#if (PY_VERSION_HEX < 0x02050000 )
564
- "O|i:from_buffer " ,
570
+ "O|i:from_buffer_copy " ,
565
571
#else
566
- "O|n:from_buffer " ,
572
+ "O|n:from_buffer_copy " ,
567
573
#endif
568
574
& obj , & offset ))
569
575
return NULL ;
You can’t perform that action at this time.
0 commit comments