Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c468b537
Commit
c468b537
authored
Feb 01, 2015
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge 3.3 (#23364, #23363)
parents
f635dc32
0eaabf1c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
2 deletions
+32
-2
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+12
-0
Misc/NEWS
Misc/NEWS
+4
-0
Modules/itertoolsmodule.c
Modules/itertoolsmodule.c
+16
-2
No files found.
Lib/test/test_itertools.py
View file @
c468b537
...
...
@@ -426,6 +426,13 @@ class TestBasicOps(unittest.TestCase):
for
proto
in
range
(
pickle
.
HIGHEST_PROTOCOL
+
1
):
self
.
pickletest
(
proto
,
permutations
(
values
,
r
))
# test pickling
@
support
.
bigaddrspacetest
def
test_permutations_overflow
(
self
):
with
self
.
assertRaises
(
OverflowError
):
permutations
(
"A"
,
2
**
30
)
with
self
.
assertRaises
(
OverflowError
):
permutations
(
"A"
,
2
,
2
**
30
)
@
support
.
impl_detail
(
"tuple reuse is specific to CPython"
)
def
test_permutations_tuple_reuse
(
self
):
self
.
assertEqual
(
len
(
set
(
map
(
id
,
permutations
(
'abcde'
,
3
)))),
1
)
...
...
@@ -955,6 +962,11 @@ class TestBasicOps(unittest.TestCase):
args
=
map
(
iter
,
args
)
self
.
assertEqual
(
len
(
list
(
product
(
*
args
))),
expected_len
)
@
support
.
bigaddrspacetest
def
test_product_overflow
(
self
):
with
self
.
assertRaises
(
OverflowError
):
product
([
"a"
]
*
(
2
**
16
),
repeat
=
2
**
16
)
@
support
.
impl_detail
(
"tuple reuse is specific to CPython"
)
def
test_product_tuple_reuse
(
self
):
self
.
assertEqual
(
len
(
set
(
map
(
id
,
product
(
'abc'
,
'def'
)))),
1
)
...
...
Misc/NEWS
View file @
c468b537
...
...
@@ -50,6 +50,10 @@ Core and Builtins
Library
-------
- Issue #23363: Fix possible overflow in itertools.permutations.
- Issue #23364: Fix possible overflow in itertools.product.
- Issue #23366: Fixed possible integer overflow in itertools.combinations.
- Issue #23366: Fixed possible integer overflow in itertools.combinations.
...
...
Modules/itertoolsmodule.c
View file @
c468b537
...
...
@@ -2017,8 +2017,17 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
}
}
assert
(
PyTuple_Check
(
args
));
nargs
=
(
repeat
==
0
)
?
0
:
PyTuple_GET_SIZE
(
args
);
assert
(
PyTuple_CheckExact
(
args
));
if
(
repeat
==
0
)
{
nargs
=
0
;
}
else
{
nargs
=
PyTuple_GET_SIZE
(
args
);
if
(
repeat
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
)
||
nargs
>
PY_SSIZE_T_MAX
/
(
repeat
*
sizeof
(
Py_ssize_t
)))
{
PyErr_SetString
(
PyExc_OverflowError
,
"repeat argument too large"
);
return
NULL
;
}
}
npools
=
nargs
*
repeat
;
indices
=
PyMem_Malloc
(
npools
*
sizeof
(
Py_ssize_t
));
...
...
@@ -3049,6 +3058,11 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto
error
;
}
if
(
n
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
)
||
r
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
))
{
PyErr_SetString
(
PyExc_OverflowError
,
"parameters too large"
);
goto
error
;
}
indices
=
PyMem_Malloc
(
n
*
sizeof
(
Py_ssize_t
));
cycles
=
PyMem_Malloc
(
r
*
sizeof
(
Py_ssize_t
));
if
(
indices
==
NULL
||
cycles
==
NULL
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment