cpython: 356ed025dbae (original) (raw)
Mercurial > cpython
changeset 94476:356ed025dbae 3.3
Issues #23363, #23364, #23365, #23366: Fixed itertools overflow tests. Used PyMem_New to check overflow. [#23363]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Tue, 03 Feb 2015 01:34:09 +0200 |
parents | 5c730d30ffbc |
children | 98c720c3e061 ab2e79c6cf6b |
files | Lib/test/test_itertools.py Modules/itertoolsmodule.c |
diffstat | 2 files changed, 11 insertions(+), 27 deletions(-)[+] [-] Lib/test/test_itertools.py 12 Modules/itertoolsmodule.c 26 |
line wrap: on
line diff
--- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -260,7 +260,7 @@ class TestBasicOps(unittest.TestCase): @support.bigaddrspacetest def test_combinations_overflow(self):
with self.assertRaises(OverflowError):[](#l1.7)
with self.assertRaises((OverflowError, MemoryError)):[](#l1.8) combinations("AA", 2**29)[](#l1.9)
# Test implementation detail: tuple re-use @@ -346,7 +346,7 @@ class TestBasicOps(unittest.TestCase): @support.bigaddrspacetest def test_combinations_with_replacement_overflow(self):
with self.assertRaises(OverflowError):[](#l1.16)
with self.assertRaises((OverflowError, MemoryError)):[](#l1.17) combinations_with_replacement("AA", 2**30)[](#l1.18)
# Test implementation detail: tuple re-use @@ -420,10 +420,8 @@ class TestBasicOps(unittest.TestCase): @support.bigaddrspacetest def test_permutations_overflow(self):
with self.assertRaises(OverflowError):[](#l1.25)
with self.assertRaises((OverflowError, MemoryError)):[](#l1.26) permutations("A", 2**30)[](#l1.27)
with self.assertRaises(OverflowError):[](#l1.28)
permutations("A", 2, 2**30)[](#l1.29)
@support.impl_detail("tuple resuse is CPython specific") def test_permutations_tuple_reuse(self): @@ -939,8 +937,8 @@ class TestBasicOps(unittest.TestCase): @support.bigaddrspacetest def test_product_overflow(self):
with self.assertRaises(OverflowError):[](#l1.37)
product(["a"]*(2**16), repeat=2**16)[](#l1.38)
with self.assertRaises((OverflowError, MemoryError)):[](#l1.39)
product(*(['ab']*2**5), repeat=2**25)[](#l1.40)
@support.impl_detail("tuple reuse is specific to CPython") def test_product_tuple_reuse(self):
--- a/Modules/itertoolsmodule.c +++ b/Modules/itertoolsmodule.c @@ -2003,15 +2003,14 @@ product_new(PyTypeObject *type, PyObject nargs = 0; } else { nargs = PyTuple_GET_SIZE(args);
if (repeat > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) ||[](#l2.7)
nargs > PY_SSIZE_T_MAX/(repeat * sizeof(Py_ssize_t))) {[](#l2.8)
} npools = nargs * repeat;if ((size_t)nargs > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)/repeat) {[](#l2.9) PyErr_SetString(PyExc_OverflowError, "repeat argument too large");[](#l2.10) return NULL;[](#l2.11) }[](#l2.12)
@@ -2335,11 +2334,7 @@ combinations_new(PyTypeObject *type, PyO goto error; }
- if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
PyErr_SetString(PyExc_OverflowError, "r is too big");[](#l2.26)
goto error;[](#l2.27)
- }
- indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
@@ -2668,11 +2663,7 @@ cwr_new(PyTypeObject *type, PyObject *ar goto error; }
- if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
PyErr_SetString(PyExc_OverflowError, "r is too big");[](#l2.39)
goto error;[](#l2.40)
- }
- indices = PyMem_Malloc(r * sizeof(Py_ssize_t));
@@ -3001,13 +2992,8 @@ permutations_new(PyTypeObject *type, PyO goto error; }