diff options
author | Zackery Spytz <zspytz@gmail.com> | 2019-05-17 01:13:03 -0600 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2019-05-17 10:13:03 +0300 |
commit | 14514d9084a40f599c57da853a305aa264562a43 (patch) | |
tree | 36cb61b74dbfda9ce1cdf72a864b640d0bda546d /Objects/bytearrayobject.c | |
parent | 870b035bc6da96689b59dd6f79782ec6f1873617 (diff) | |
download | cpython-git-14514d9084a40f599c57da853a305aa264562a43.tar.gz |
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 'Objects/bytearrayobject.c')
-rw-r--r-- | Objects/bytearrayobject.c | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index eaf5dceb03..8d5ba54012 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -410,7 +410,8 @@ bytearray_subscript(PyByteArrayObject *self, PyObject *index) return PyLong_FromLong((unsigned char)(PyByteArray_AS_STRING(self)[i])); } else if (PySlice_Check(index)) { - Py_ssize_t start, stop, step, slicelength, cur, i; + Py_ssize_t start, stop, step, slicelength, i; + size_t cur; if (PySlice_Unpack(index, &start, &stop, &step) < 0) { return NULL; } |