diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py index dc9e28d209c..3f56c71a51d 100644 --- a/Tests/test_imagepath.py +++ b/Tests/test_imagepath.py @@ -203,10 +203,8 @@ def test_transform_with_wrap() -> None: def test_overflow_segfault() -> None: - # Some Pythons fail getting the argument as an integer, and it falls - # through to the sequence. Seeing this on 32-bit Windows. - with pytest.raises((TypeError, MemoryError)): - # post patch, this fails with a memory error + with pytest.raises((OverflowError, MemoryError)): + # post patch, this fails with a memory error on 64-bit x = Evil() # This fails due to the invalid malloc above, diff --git a/src/path.c b/src/path.c index e5f2c0ef061..c9c02663c1b 100644 --- a/src/path.c +++ b/src/path.c @@ -282,8 +282,16 @@ PyPath_Create(PyObject *self, PyObject *args) { Py_ssize_t count; double *xy; - if (PyArg_ParseTuple(args, "n:Path", &count)) { + if (!PyArg_ParseTuple(args, "O", &data)) { + return NULL; + } + if (PyLong_Check(data)) { /* number of vertices */ + count = PyLong_AsSsize_t(data); + if (PyErr_Occurred()) { + return NULL; + } + xy = alloc_array(count); if (!xy) { return NULL; @@ -291,11 +299,6 @@ PyPath_Create(PyObject *self, PyObject *args) { } else { /* sequence or other path */ - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "O", &data)) { - return NULL; - } - count = PyPath_Flatten(data, &xy); if (count < 0) { return NULL;