summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2011-09-24 07:56:09 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2011-09-24 07:56:09 (GMT)
commitb2f6bc72a269a0c4ed389ad232b47e2a42b8dde0 (patch)
treeb1e691ab2afcc804385f38036708f598377a0051
parentadde86d0e31ce486e72a9d1a2a7625e5e34d97e9 (diff)
downloadcpython-b2f6bc72a269a0c4ed389ad232b47e2a42b8dde0.zip
cpython-b2f6bc72a269a0c4ed389ad232b47e2a42b8dde0.tar.gz
cpython-b2f6bc72a269a0c4ed389ad232b47e2a42b8dde0.tar.bz2
Issue #12973: Fix itertools bug caused by signed integer overflow. Thanks Stefan Krah.
-rw-r--r--Misc/NEWS6
-rw-r--r--Modules/itertoolsmodule.c4
2 files changed, 6 insertions, 4 deletions
diff --git a/Misc/NEWS b/Misc/NEWS
index fd98d02..1b03736 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,9 +17,9 @@ Core and Builtins
- Issue #13021: Missing decref on an error path. Thanks to Suman Saha for
finding the bug and providing a patch.
-- Issue #12973: Fix overflow check that relied on undefined behaviour in
- list_repeat. This bug caused test_list to fail with recent versions
- of Clang.
+- Issue #12973: Fix overflow checks that relied on undefined behaviour in
+ list_repeat (listobject.c) and islice_next (itertoolsmodule.c). These bugs
+ caused test failures with recent versions of Clang.
- Issue #12802: the Windows error ERROR_DIRECTORY (numbered 267) is now
mapped to POSIX errno ENOTDIR (previously EINVAL).
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 71d5bb6..8b6fa85 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -1234,7 +1234,9 @@ islice_next(isliceobject *lz)
return NULL;
lz->cnt++;
oldnext = lz->next;
- lz->next += lz->step;
+ /* The (size_t) cast below avoids the danger of undefined
+ behaviour from signed integer overflow. */
+ lz->next += (size_t)lz->step;
if (lz->next < oldnext || (stop != -1 && lz->next > stop))
lz->next = stop;
return item;