| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -426,6 +426,13 @@ def permutations2(iterable, r=None): | |||
| 426 | 426 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): | |
| 427 | 427 | self.pickletest(proto, permutations(values, r)) # test pickling | |
| 428 | 428 | ||
| 429 | + @support.bigaddrspacetest | ||
| 430 | + def test_permutations_overflow(self): | ||
| 431 | + with self.assertRaises(OverflowError): | ||
| 432 | + permutations("A", 2**30) | ||
| 433 | + with self.assertRaises(OverflowError): | ||
| 434 | + permutations("A", 2, 2**30) | ||
| 435 | + | ||
| 429 | 436 | @support.impl_detail("tuple reuse is specific to CPython") | |
| 430 | 437 | def test_permutations_tuple_reuse(self): | |
| 431 | 438 | self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1) | |
@@ -955,6 +962,11 @@ def product2(*args, **kwds): | |||
| 955 | 962 | args = map(iter, args) | |
| 956 | 963 | self.assertEqual(len(list(product(*args))), expected_len) | |
| 957 | 964 | ||
| 965 | + @support.bigaddrspacetest | ||
| 966 | + def test_product_overflow(self): | ||
| 967 | + with self.assertRaises(OverflowError): | ||
| 968 | + product(["a"]*(2**16), repeat=2**16) | ||
| 969 | + | ||
| 958 | 970 | @support.impl_detail("tuple reuse is specific to CPython") | |
| 959 | 971 | def test_product_tuple_reuse(self): | |
| 960 | 972 | self.assertEqual(len(set(map(id, product('abc', 'def')))), 1) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,10 @@ Core and Builtins | |||
| 50 | 50 | Library | |
| 51 | 51 | ------- | |
| 52 | 52 | ||
| 53 | + - Issue #23363: Fix possible overflow in itertools.permutations. | ||
| 54 | + | ||
| 55 | + - Issue #23364: Fix possible overflow in itertools.product. | ||
| 56 | + | ||
| 53 | 57 | - Issue #23366: Fixed possible integer overflow in itertools.combinations. | |
| 54 | 58 | ||
| 55 | 59 | - Issue #23366: Fixed possible integer overflow in itertools.combinations. | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2017,8 +2017,17 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |||
| 2017 | 2017 | } | |
| 2018 | 2018 | } | |
| 2019 | 2019 | ||
| 2020 | - assert(PyTuple_Check(args)); | ||
| 2021 | - nargs = (repeat == 0) ? 0 : PyTuple_GET_SIZE(args); | ||
| 2020 | + assert(PyTuple_CheckExact(args)); | ||
| 2021 | + if (repeat == 0) { | ||
| 2022 | + nargs = 0; | ||
| 2023 | + } else { | ||
| 2024 | + nargs = PyTuple_GET_SIZE(args); | ||
| 2025 | + if (repeat > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) || | ||
| 2026 | + nargs > PY_SSIZE_T_MAX/(repeat * sizeof(Py_ssize_t))) { | ||
| 2027 | + PyErr_SetString(PyExc_OverflowError, "repeat argument too large"); | ||
| 2028 | + return NULL; | ||
| 2029 | + } | ||
| 2030 | + } | ||
| 2022 | 2031 | npools = nargs * repeat; | |
| 2023 | 2032 | ||
| 2024 | 2033 | indices = PyMem_Malloc(npools * sizeof(Py_ssize_t)); | |
@@ -3049,6 +3058,11 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds) | |||
| 3049 | 3058 | goto error; | |
| 3050 | 3059 | } | |
| 3051 | 3060 | ||
| 3061 | + if (n > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) || | ||
| 3062 | + r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) { | ||
| 3063 | + PyErr_SetString(PyExc_OverflowError, "parameters too large"); | ||
| 3064 | + goto error; | ||
| 3065 | + } | ||
| 3052 | 3066 | indices = PyMem_Malloc(n * sizeof(Py_ssize_t)); | |
| 3053 | 3067 | cycles = PyMem_Malloc(r * sizeof(Py_ssize_t)); | |
| 3054 | 3068 | if (indices == NULL || cycles == NULL) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments