summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.c
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-07-18 08:18:32 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-07-18 08:18:32 (GMT)
commitbd09f15b691853968ada24dcc8a4b2dc50d8d6f2 (patch)
treefdbdec9caca85698a3731935ac953be8082c1957 /Objects/bytearrayobject.c
parent5e24b98fc3dcb66336fc1ebf42e93fd9a7ed4a86 (diff)
parent371731ebfdc3ee754af8cda72dc7ee5442c7491b (diff)
downloadcpython-bd09f15b691853968ada24dcc8a4b2dc50d8d6f2.zip
cpython-bd09f15b691853968ada24dcc8a4b2dc50d8d6f2.tar.gz
cpython-bd09f15b691853968ada24dcc8a4b2dc50d8d6f2.tar.bz2
Issue #27507: Merge overflow check from 3.5
Diffstat (limited to 'Objects/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 4990b3e..f8c21d4 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -1642,7 +1642,17 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
Py_DECREF(item);
if (len >= buf_size) {
- buf_size = len + (len >> 1) + 1;
+ Py_ssize_t addition;
+ if (len == PY_SSIZE_T_MAX) {
+ Py_DECREF(it);
+ Py_DECREF(bytearray_obj);
+ return PyErr_NoMemory();
+ }
+ addition = len >> 1;
+ if (addition > PY_SSIZE_T_MAX - len - 1)
+ buf_size = PY_SSIZE_T_MAX;
+ else
+ buf_size = len + addition + 1;
if (PyByteArray_Resize((PyObject *)bytearray_obj, buf_size) < 0) {
Py_DECREF(it);
Py_DECREF(bytearray_obj);