Issue #12973: Fix itertools bug caused by signed integer overflow. Thanks Stefan Krah.
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 @@
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;