diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-05-17 07:13:03 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2019-05-17 07:13:03 (GMT) |
commit | 14514d9084a40f599c57da853a305aa264562a43 (patch) | |
tree | 36cb61b74dbfda9ce1cdf72a864b640d0bda546d /Modules | |
parent | 870b035bc6da96689b59dd6f79782ec6f1873617 (diff) | |
download | cpython-14514d9084a40f599c57da853a305aa264562a43.zip cpython-14514d9084a40f599c57da853a305aa264562a43.tar.gz cpython-14514d9084a40f599c57da853a305aa264562a43.tar.bz2 |
bpo-36946: Fix possible signed integer overflow when handling slices. (GH-13375)
The final addition (cur += step) may overflow, so use size_t for "cur".
"cur" is always positive (even for negative steps), so it is safe to use
size_t here.
Co-Authored-By: Martin Panter <vadmium+py@gmail.com>
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_ctypes/_ctypes.c | 6 | ||||
-rw-r--r-- | Modules/_elementtree.c | 6 | ||||
-rw-r--r-- | Modules/arraymodule.c | 6 | ||||
-rw-r--r-- | Modules/mmapmodule.c | 6 |
4 files changed, 16 insertions, 8 deletions
diff --git a/Modules/_ctypes/_ctypes.c b/Modules/_ctypes/_ctypes.c index 13cf76a..7b51153 100644 --- a/Modules/_ctypes/_ctypes.c +++ b/Modules/_ctypes/_ctypes.c @@ -4487,7 +4487,8 @@ Array_subscript(PyObject *myself, PyObject *item) StgDictObject *stgdict, *itemdict; PyObject *proto; PyObject *np; - Py_ssize_t start, stop, step, slicelen, cur, i; + Py_ssize_t start, stop, step, slicelen, i; + size_t cur; if (PySlice_Unpack(item, &start, &stop, &step) < 0) { return NULL; @@ -4627,7 +4628,8 @@ Array_ass_subscript(PyObject *myself, PyObject *item, PyObject *value) return Array_ass_item(myself, i, value); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelen, otherlen, i, cur; + Py_ssize_t start, stop, step, slicelen, otherlen, i; + size_t cur; if (PySlice_Unpack(item, &start, &stop, &step) < 0) { return -1; diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index f5fc443..b1fb3ee 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1809,7 +1809,8 @@ element_subscr(PyObject* self_, PyObject* item) return element_getitem(self_, i); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelen, cur, i; + Py_ssize_t start, stop, step, slicelen, i; + size_t cur; PyObject* list; if (!self->extra) @@ -1861,7 +1862,8 @@ element_ass_subscr(PyObject* self_, PyObject* item, PyObject* value) return element_setitem(self_, i, value); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelen, newlen, cur, i; + Py_ssize_t start, stop, step, slicelen, newlen, i; + size_t cur; PyObject* recycle = NULL; PyObject* seq; diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 4be3beb..523afb9 100644 --- a/Modules/arraymodule.c +++ b/Modules/arraymodule.c @@ -2343,7 +2343,8 @@ array_subscr(arrayobject* self, PyObject* item) return array_item(self, i); } else if (PySlice_Check(item)) { - Py_ssize_t start, stop, step, slicelength, cur, i; + Py_ssize_t start, stop, step, slicelength, i; + size_t cur; PyObject* result; arrayobject* ar; int itemsize = self->ob_descr->itemsize; @@ -2527,7 +2528,8 @@ array_ass_subscr(arrayobject* self, PyObject* item, PyObject* value) return 0; } else { - Py_ssize_t cur, i; + size_t cur; + Py_ssize_t i; if (needed != slicelength) { PyErr_Format(PyExc_ValueError, diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c index 6ddbf70..33366b2 100644 --- a/Modules/mmapmodule.c +++ b/Modules/mmapmodule.c @@ -806,7 +806,8 @@ mmap_subscript(mmap_object *self, PyObject *item) slicelen); else { char *result_buf = (char *)PyMem_Malloc(slicelen); - Py_ssize_t cur, i; + size_t cur; + Py_ssize_t i; PyObject *result; if (result_buf == NULL) @@ -926,7 +927,8 @@ mmap_ass_subscript(mmap_object *self, PyObject *item, PyObject *value) memcpy(self->data + start, vbuf.buf, slicelen); } else { - Py_ssize_t cur, i; + size_t cur; + Py_ssize_t i; for (cur = start, i = 0; i < slicelen; |