Mercurial > cpython-lru_cache-weakref
diff Objects/tupleobject.c @ 79529:152d85b2da3a 3.3
Issue #16096: Fix several occurrences of potential signed integer overflow. Thanks Serhiy Storchaka.
| author | Mark Dickinson <mdickinson@enthought.com> |
|---|---|
| date | Sat, 06 Oct 2012 18:04:49 +0100 |
| parents | 033b409f7cd6 |
| children | 8b4fff41dee5 |
line wrap: on
line diff
--- a/Objects/tupleobject.c Sat Oct 06 18:45:47 2012 +0300 +++ b/Objects/tupleobject.c Sat Oct 06 18:04:49 2012 +0100 @@ -96,15 +96,11 @@ else #endif { - Py_ssize_t nbytes = size * sizeof(PyObject *); /* Check for overflow */ - if (nbytes / sizeof(PyObject *) != (size_t)size || - (nbytes > PY_SSIZE_T_MAX - sizeof(PyTupleObject) - sizeof(PyObject *))) - { + if (size > (PY_SSIZE_T_MAX - sizeof(PyTupleObject) - + sizeof(PyObject *)) / sizeof(PyObject *)) { return PyErr_NoMemory(); } - /* nbytes += sizeof(PyTupleObject) - sizeof(PyObject *); */ - op = PyObject_GC_NewVar(PyTupleObject, &PyTuple_Type, size); if (op == NULL) return NULL; @@ -481,9 +477,9 @@ if (Py_SIZE(a) == 0) return PyTuple_New(0); } + if (n > PY_SSIZE_T_MAX / Py_SIZE(a)) + return PyErr_NoMemory(); size = Py_SIZE(a) * n; - if (size/Py_SIZE(a) != n) - return PyErr_NoMemory(); np = (PyTupleObject *) PyTuple_New(size); if (np == NULL) return NULL;
