[Python-checkins] cpython (3.3): check for overflow in combinations_with_replacement (closes #23365)
benjamin.peterson
python-checkins at python.org
Mon Feb 2 03:13:50 CET 2015
https://hg.python.org/cpython/rev/93d445cd5f70
changeset: 94452:93d445cd5f70
branch: 3.3
parent: 94448:014886dae5c4
user: Benjamin Peterson <benjamin at python.org>
date: Sun Feb 01 21:10:47 2015 -0500
summary:
check for overflow in combinations_with_replacement (closes #23365)
files:
Lib/test/test_itertools.py | 6 +++++-
Misc/NEWS | 3 +++
Modules/itertoolsmodule.c | 4 ++++
3 files changed, 12 insertions(+), 1 deletions(-)
diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py
--- a/Lib/test/test_itertools.py
+++ b/Lib/test/test_itertools.py
@@ -344,8 +344,12 @@
self.pickletest(cwr(values,r)) # test pickling
+ @support.bigaddrspacetest
+ def test_combinations_with_replacement_overflow(self):
+ with self.assertRaises(OverflowError):
+ combinations_with_replacement("AA", 2**30)
+
# Test implementation detail: tuple re-use
-
@support.impl_detail("tuple reuse is specific to CPython")
def test_combinations_with_replacement_tuple_reuse(self):
cwr = combinations_with_replacement
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -21,6 +21,9 @@
- Issue #23366: Fixed possible integer overflow in itertools.combinations.
+- Issue #23365: Fixed possible integer overflow in
+ itertools.combinations_with_replacement.
+
What's New in Python 3.3.6?
===========================
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -2659,6 +2659,10 @@
goto error;
}
+ if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
+ PyErr_SetString(PyExc_OverflowError, "r is too big");
+ goto error;
+ }
indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
if (indices == NULL) {
PyErr_NoMemory();
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list