| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 395733d commit 6e723d2
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -120,5 +120,13 @@ def test_from_buffer_copy_with_offset(self): | |||
| 120 | 120 | with self.assertRaises(ValueError): | |
| 121 | 121 | (c_int * 1).from_buffer_copy(a, 16 * sizeof(c_int)) | |
| 122 | 122 | ||
| 123 | + def test_abstract(self): | ||
| 124 | + self.assertRaises(TypeError, Array.from_buffer, bytearray(10)) | ||
| 125 | + self.assertRaises(TypeError, Structure.from_buffer, bytearray(10)) | ||
| 126 | + self.assertRaises(TypeError, Union.from_buffer, bytearray(10)) | ||
| 127 | + self.assertRaises(TypeError, Array.from_buffer_copy, b"123") | ||
| 128 | + self.assertRaises(TypeError, Structure.from_buffer_copy, b"123") | ||
| 129 | + self.assertRaises(TypeError, Union.from_buffer_copy, b"123") | ||
| 130 | + | ||
| 123 | 131 | if __name__ == '__main__': | |
| 124 | 132 | unittest.main() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -121,6 +121,9 @@ Core and Builtins | |||
| 121 | 121 | Library | |
| 122 | 122 | ------- | |
| 123 | 123 | ||
| 124 | + - Issue #25659: In ctypes, prevent a crash calling the from_buffer() and | ||
| 125 | + from_buffer_copy() methods on abstract classes like Array. | ||
| 126 | + | ||
| 124 | 127 | - Issue #28732: Fix crash in os.spawnv() with no elements in args | |
| 125 | 128 | ||
| 126 | 129 | - Issue #28485: Always raise ValueError for negative | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -469,7 +469,10 @@ CDataType_from_buffer(PyObject *type, PyObject *args) | |||
| 469 | 469 | Py_ssize_t offset = 0; | |
| 470 | 470 | ||
| 471 | 471 | StgDictObject *dict = PyType_stgdict(type); | |
| 472 | - assert (dict); | ||
| 472 | + if (!dict) { | ||
| 473 | + PyErr_SetString(PyExc_TypeError, "abstract class"); | ||
| 474 | + return NULL; | ||
| 475 | + } | ||
| 473 | 476 | ||
| 474 | 477 | if (!PyArg_ParseTuple(args, "O|n:from_buffer", &obj, &offset)) | |
| 475 | 478 | return NULL; | |
@@ -537,9 +540,12 @@ CDataType_from_buffer_copy(PyObject *type, PyObject *args) | |||
| 537 | 540 | Py_ssize_t offset = 0; | |
| 538 | 541 | PyObject *result; | |
| 539 | 542 | StgDictObject *dict = PyType_stgdict(type); | |
| 540 | - assert (dict); | ||
| 543 | + if (!dict) { | ||
| 544 | + PyErr_SetString(PyExc_TypeError, "abstract class"); | ||
| 545 | + return NULL; | ||
| 546 | + } | ||
| 541 | 547 | ||
| 542 | - if (!PyArg_ParseTuple(args, "y*|n:from_buffer", &buffer, &offset)) | ||
| 548 | + if (!PyArg_ParseTuple(args, "y*|n:from_buffer_copy", &buffer, &offset)) | ||
| 543 | 549 | return NULL; | |
| 544 | 550 | ||
| 545 | 551 | if (offset < 0) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments