Skip to content

Commit da60ab6

Browse files
authored
Raise OverflowError if number of vertices is too large for Path (#9729)
1 parent 4fe7aae commit da60ab6

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

Tests/test_imagepath.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,8 @@ def test_transform_with_wrap() -> None:
203203

204204

205205
def test_overflow_segfault() -> None:
206-
# Some Pythons fail getting the argument as an integer, and it falls
207-
# through to the sequence. Seeing this on 32-bit Windows.
208-
with pytest.raises((TypeError, MemoryError)):
209-
# post patch, this fails with a memory error
206+
with pytest.raises((OverflowError, MemoryError)):
207+
# post patch, this fails with a memory error on 64-bit
210208
x = Evil()
211209

212210
# This fails due to the invalid malloc above,

src/path.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,20 +282,23 @@ PyPath_Create(PyObject *self, PyObject *args) {
282282
Py_ssize_t count;
283283
double *xy;
284284

285-
if (PyArg_ParseTuple(args, "n:Path", &count)) {
285+
if (!PyArg_ParseTuple(args, "O", &data)) {
286+
return NULL;
287+
}
288+
if (PyLong_Check(data)) {
286289
/* number of vertices */
290+
count = PyLong_AsSsize_t(data);
291+
if (PyErr_Occurred()) {
292+
return NULL;
293+
}
294+
287295
xy = alloc_array(count);
288296
if (!xy) {
289297
return NULL;
290298
}
291299

292300
} else {
293301
/* sequence or other path */
294-
PyErr_Clear();
295-
if (!PyArg_ParseTuple(args, "O", &data)) {
296-
return NULL;
297-
}
298-
299302
count = PyPath_Flatten(data, &xy);
300303
if (count < 0) {
301304
return NULL;

0 commit comments

Comments
 (0)