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
85370109
Commit
85370109
authored
Feb 03, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issues #23363, #23364, #23365, #23366: Fixed itertools overflow tests.
Used PyMem_New to check overflow.
parent
2a864a10
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
27 deletions
+11
-27
Lib/test/test_itertools.py
Lib/test/test_itertools.py
+5
-7
Modules/itertoolsmodule.c
Modules/itertoolsmodule.c
+6
-20
No files found.
Lib/test/test_itertools.py
View file @
85370109
...
@@ -260,7 +260,7 @@ class TestBasicOps(unittest.TestCase):
...
@@ -260,7 +260,7 @@ class TestBasicOps(unittest.TestCase):
@
support
.
bigaddrspacetest
@
support
.
bigaddrspacetest
def
test_combinations_overflow
(
self
):
def
test_combinations_overflow
(
self
):
with
self
.
assertRaises
(
OverflowError
):
with
self
.
assertRaises
(
(
OverflowError
,
MemoryError
)
):
combinations
(
"AA"
,
2
**
29
)
combinations
(
"AA"
,
2
**
29
)
# Test implementation detail: tuple re-use
# Test implementation detail: tuple re-use
...
@@ -346,7 +346,7 @@ class TestBasicOps(unittest.TestCase):
...
@@ -346,7 +346,7 @@ class TestBasicOps(unittest.TestCase):
@
support
.
bigaddrspacetest
@
support
.
bigaddrspacetest
def
test_combinations_with_replacement_overflow
(
self
):
def
test_combinations_with_replacement_overflow
(
self
):
with
self
.
assertRaises
(
OverflowError
):
with
self
.
assertRaises
(
(
OverflowError
,
MemoryError
)
):
combinations_with_replacement
(
"AA"
,
2
**
30
)
combinations_with_replacement
(
"AA"
,
2
**
30
)
# Test implementation detail: tuple re-use
# Test implementation detail: tuple re-use
...
@@ -420,10 +420,8 @@ class TestBasicOps(unittest.TestCase):
...
@@ -420,10 +420,8 @@ class TestBasicOps(unittest.TestCase):
@
support
.
bigaddrspacetest
@
support
.
bigaddrspacetest
def
test_permutations_overflow
(
self
):
def
test_permutations_overflow
(
self
):
with
self
.
assertRaises
(
OverflowError
):
with
self
.
assertRaises
(
(
OverflowError
,
MemoryError
)
):
permutations
(
"A"
,
2
**
30
)
permutations
(
"A"
,
2
**
30
)
with
self
.
assertRaises
(
OverflowError
):
permutations
(
"A"
,
2
,
2
**
30
)
@
support
.
impl_detail
(
"tuple resuse is CPython specific"
)
@
support
.
impl_detail
(
"tuple resuse is CPython specific"
)
def
test_permutations_tuple_reuse
(
self
):
def
test_permutations_tuple_reuse
(
self
):
...
@@ -939,8 +937,8 @@ class TestBasicOps(unittest.TestCase):
...
@@ -939,8 +937,8 @@ class TestBasicOps(unittest.TestCase):
@
support
.
bigaddrspacetest
@
support
.
bigaddrspacetest
def
test_product_overflow
(
self
):
def
test_product_overflow
(
self
):
with
self
.
assertRaises
(
OverflowError
):
with
self
.
assertRaises
(
(
OverflowError
,
MemoryError
)
):
product
(
[
"a"
]
*
(
2
**
16
),
repeat
=
2
**
16
)
product
(
*
([
'ab'
]
*
2
**
5
),
repeat
=
2
**
25
)
@
support
.
impl_detail
(
"tuple reuse is specific to CPython"
)
@
support
.
impl_detail
(
"tuple reuse is specific to CPython"
)
def
test_product_tuple_reuse
(
self
):
def
test_product_tuple_reuse
(
self
):
...
...
Modules/itertoolsmodule.c
View file @
85370109
...
@@ -2003,15 +2003,14 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2003,15 +2003,14 @@ product_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
nargs
=
0
;
nargs
=
0
;
}
else
{
}
else
{
nargs
=
PyTuple_GET_SIZE
(
args
);
nargs
=
PyTuple_GET_SIZE
(
args
);
if
(
repeat
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
)
||
if
((
size_t
)
nargs
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
)
/
repeat
)
{
nargs
>
PY_SSIZE_T_MAX
/
(
repeat
*
sizeof
(
Py_ssize_t
)))
{
PyErr_SetString
(
PyExc_OverflowError
,
"repeat argument too large"
);
PyErr_SetString
(
PyExc_OverflowError
,
"repeat argument too large"
);
return
NULL
;
return
NULL
;
}
}
}
}
npools
=
nargs
*
repeat
;
npools
=
nargs
*
repeat
;
indices
=
PyMem_
Malloc
(
npools
*
sizeof
(
Py_ssize_t
)
);
indices
=
PyMem_
New
(
Py_ssize_t
,
npools
);
if
(
indices
==
NULL
)
{
if
(
indices
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
goto
error
;
goto
error
;
...
@@ -2335,11 +2334,7 @@ combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2335,11 +2334,7 @@ combinations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto
error
;
goto
error
;
}
}
if
(
r
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
))
{
indices
=
PyMem_New
(
Py_ssize_t
,
r
);
PyErr_SetString
(
PyExc_OverflowError
,
"r is too big"
);
goto
error
;
}
indices
=
PyMem_Malloc
(
r
*
sizeof
(
Py_ssize_t
));
if
(
indices
==
NULL
)
{
if
(
indices
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
goto
error
;
goto
error
;
...
@@ -2668,11 +2663,7 @@ cwr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -2668,11 +2663,7 @@ cwr_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto
error
;
goto
error
;
}
}
if
(
r
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
))
{
indices
=
PyMem_New
(
Py_ssize_t
,
r
);
PyErr_SetString
(
PyExc_OverflowError
,
"r is too big"
);
goto
error
;
}
indices
=
PyMem_Malloc
(
r
*
sizeof
(
Py_ssize_t
));
if
(
indices
==
NULL
)
{
if
(
indices
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
goto
error
;
goto
error
;
...
@@ -3001,13 +2992,8 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
...
@@ -3001,13 +2992,8 @@ permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
goto
error
;
goto
error
;
}
}
if
(
n
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
)
||
indices
=
PyMem_New
(
Py_ssize_t
,
n
);
r
>
PY_SSIZE_T_MAX
/
sizeof
(
Py_ssize_t
))
{
cycles
=
PyMem_New
(
Py_ssize_t
,
r
);
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
)
{
if
(
indices
==
NULL
||
cycles
==
NULL
)
{
PyErr_NoMemory
();
PyErr_NoMemory
();
goto
error
;
goto
error
;
...
...
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