Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bd09f15

Browse files
committed
Issue #27507: Merge overflow check from 3.5
2 parents 5e24b98 + 371731e commit bd09f15

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ What's New in Python 3.6.0 alpha 4
1010
Core and Builtins
1111
-----------------
1212

13+
- Issue #27507: Add integer overflow check in bytearray.extend(). Patch by
14+
Xiang Zhang.
15+
1316
- Issue #27419: Standard __import__() no longer look up "__import__" in globals
1417
or builtins for importing submodules or "from import". Fixed a crash if
1518
raise a warning about unabling to resolve package from __spec__ or

Objects/bytearrayobject.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1642,7 +1642,17 @@ bytearray_extend(PyByteArrayObject *self, PyObject *iterable_of_ints)
16421642
Py_DECREF(item);
16431643

16441644
if (len >= buf_size) {
1645-
buf_size = len + (len >> 1) + 1;
1645+
Py_ssize_t addition;
1646+
if (len == PY_SSIZE_T_MAX) {
1647+
Py_DECREF(it);
1648+
Py_DECREF(bytearray_obj);
1649+
return PyErr_NoMemory();
1650+
}
1651+
addition = len >> 1;
1652+
if (addition > PY_SSIZE_T_MAX - len - 1)
1653+
buf_size = PY_SSIZE_T_MAX;
1654+
else
1655+
buf_size = len + addition + 1;
16461656
if (PyByteArray_Resize((PyObject *)bytearray_obj, buf_size) < 0) {
16471657
Py_DECREF(it);
16481658
Py_DECREF(bytearray_obj);

0 commit comments

Comments
 (0)