summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-07-25 02:30:05 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-07-25 02:30:05 (GMT)
commite8db861f4743fa1702c3119c219c821790e11a9c (patch)
treef8966b7d5b014977ee81aae3b540d7f2c7749643 /Objects
parentaa46bd461c1b585d967b9a9497ea872097017d99 (diff)
downloadcpython-e8db861f4743fa1702c3119c219c821790e11a9c.zip
cpython-e8db861f4743fa1702c3119c219c821790e11a9c.tar.gz
cpython-e8db861f4743fa1702c3119c219c821790e11a9c.tar.bz2
Issue #27581: Don’t rely on overflow wrapping in PySequence_Tuple()
Patch by Xiang Zhang.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/abstract.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/Objects/abstract.c b/Objects/abstract.c
index 585992d..88205bd 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -1724,21 +1724,22 @@ PySequence_Tuple(PyObject *v)
break;
}
if (j >= n) {
- Py_ssize_t oldn = n;
+ size_t newn = (size_t)n;
/* The over-allocation strategy can grow a bit faster
than for lists because unlike lists the
over-allocation isn't permanent -- we reclaim
the excess before the end of this routine.
So, grow by ten and then add 25%.
*/
- n += 10;
- n += n >> 2;
- if (n < oldn) {
+ newn += 10u;
+ newn += newn >> 2;
+ if (newn > PY_SSIZE_T_MAX) {
/* Check for overflow */
PyErr_NoMemory();
Py_DECREF(item);
goto Fail;
}
+ n = (Py_ssize_t)newn;
if (_PyTuple_Resize(&result, n) != 0) {
Py_DECREF(item);
goto Fail;