mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Issue #27473: Fixed possible integer overflow in bytes and bytearray
concatenations. Patch by Xiang Zhang.
This commit is contained in:
parent
537ad7ad9f
commit
06cfb0cd70
3 changed files with 14 additions and 16 deletions
|
@ -1265,7 +1265,6 @@ bytes_length(PyBytesObject *a)
|
|||
static PyObject *
|
||||
bytes_concat(PyObject *a, PyObject *b)
|
||||
{
|
||||
Py_ssize_t size;
|
||||
Py_buffer va, vb;
|
||||
PyObject *result = NULL;
|
||||
|
||||
|
@ -1290,13 +1289,12 @@ bytes_concat(PyObject *a, PyObject *b)
|
|||
goto done;
|
||||
}
|
||||
|
||||
size = va.len + vb.len;
|
||||
if (size < 0) {
|
||||
if (va.len > PY_SSIZE_T_MAX - vb.len) {
|
||||
PyErr_NoMemory();
|
||||
goto done;
|
||||
}
|
||||
|
||||
result = PyBytes_FromStringAndSize(NULL, size);
|
||||
result = PyBytes_FromStringAndSize(NULL, va.len + vb.len);
|
||||
if (result != NULL) {
|
||||
memcpy(PyBytes_AS_STRING(result), va.buf, va.len);
|
||||
memcpy(PyBytes_AS_STRING(result) + va.len, vb.buf, vb.len);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue