Kaydet (Commit) ee6bab06 authored tarafından Guido van Rossum's avatar Guido van Rossum

Rewrite the list_inline_repeat overflow check slightly differently.

üst 1c4282b4
...@@ -490,7 +490,7 @@ list_repeat(PyListObject *a, Py_ssize_t n) ...@@ -490,7 +490,7 @@ list_repeat(PyListObject *a, Py_ssize_t n)
if (n && size/n != a->ob_size) if (n && size/n != a->ob_size)
return PyErr_NoMemory(); return PyErr_NoMemory();
if (size == 0) if (size == 0)
return PyList_New(0); return PyList_New(0);
np = (PyListObject *) PyList_New(size); np = (PyListObject *) PyList_New(size);
if (np == NULL) if (np == NULL)
return NULL; return NULL;
...@@ -672,10 +672,11 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n) ...@@ -672,10 +672,11 @@ list_inplace_repeat(PyListObject *self, Py_ssize_t n)
return (PyObject *)self; return (PyObject *)self;
} }
p = size*n; if (size > SSIZE_MAX / n) {
if (p/n != size)
return PyErr_NoMemory(); return PyErr_NoMemory();
if (list_resize(self, p) == -1) }
if (list_resize(self, size*n) == -1)
return NULL; return NULL;
p = size; p = size;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment