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
4faf5c56
Commit
4faf5c56
authored
May 21, 2015
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #23985: Fixed integer overflow in iterator object. Patch by
Clement Rouault.
parent
cbfe07e0
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
0 deletions
+34
-0
Lib/test/test_iter.py
Lib/test/test_iter.py
+25
-0
Misc/ACKS
Misc/ACKS
+1
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/iterobject.c
Objects/iterobject.c
+5
-0
No files found.
Lib/test/test_iter.py
View file @
4faf5c56
# Test iterators.
import
sys
import
unittest
from
test.support
import
run_unittest
,
TESTFN
,
unlink
,
cpython_only
import
pickle
...
...
@@ -48,6 +49,10 @@ class SequenceClass:
else
:
raise
IndexError
class
UnlimitedSequenceClass
:
def
__getitem__
(
self
,
i
):
return
i
# Main test suite
class
TestCase
(
unittest
.
TestCase
):
...
...
@@ -919,6 +924,26 @@ class TestCase(unittest.TestCase):
lst
.
extend
(
gen
())
self
.
assertEqual
(
len
(
lst
),
760
)
@
cpython_only
def
test_iter_overflow
(
self
):
# Test for the issue 22939
it
=
iter
(
UnlimitedSequenceClass
())
# Manually set `it_index` to PY_SSIZE_T_MAX-2 without a loop
it
.
__setstate__
(
sys
.
maxsize
-
2
)
self
.
assertEqual
(
next
(
it
),
sys
.
maxsize
-
2
)
self
.
assertEqual
(
next
(
it
),
sys
.
maxsize
-
1
)
with
self
.
assertRaises
(
OverflowError
):
next
(
it
)
# Check that Overflow error is always raised
with
self
.
assertRaises
(
OverflowError
):
next
(
it
)
def
test_iter_neg_setstate
(
self
):
it
=
iter
(
UnlimitedSequenceClass
())
it
.
__setstate__
(
-
42
)
self
.
assertEqual
(
next
(
it
),
0
)
self
.
assertEqual
(
next
(
it
),
1
)
def
test_main
():
run_unittest
(
TestCase
)
...
...
Misc/ACKS
View file @
4faf5c56
...
...
@@ -1168,6 +1168,7 @@ Guido van Rossum
Just van Rossum
Hugo van Rossum
Saskia van Rossum
Clement Rouault
Donald Wallace Rouse II
Liam Routt
Todd Rovito
...
...
Misc/NEWS
View file @
4faf5c56
...
...
@@ -10,6 +10,9 @@ Release date: tba
Core and Builtins
-----------------
- Issue #23985: Fixed integer overflow in iterator object. Patch by
Clement Rouault.
- Issue #23985: Fix a possible buffer overrun when deleting a slice from
the front of a bytearray and then appending some other bytes data.
...
...
Objects/iterobject.c
View file @
4faf5c56
...
...
@@ -54,6 +54,11 @@ iter_iternext(PyObject *iterator)
seq
=
it
->
it_seq
;
if
(
seq
==
NULL
)
return
NULL
;
if
(
it
->
it_index
==
PY_SSIZE_T_MAX
)
{
PyErr_SetString
(
PyExc_OverflowError
,
"iter index too large"
);
return
NULL
;
}
result
=
PySequence_GetItem
(
seq
,
it
->
it_index
);
if
(
result
!=
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