gh-126595: fix a crash when calling itertools.count(sys.maxsize)#126617
gh-126595: fix a crash when calling itertools.count(sys.maxsize)#126617vstinner merged 6 commits intopython:mainfrom
itertools.count(sys.maxsize)#126617Conversation
skirpichev
left a comment
There was a problem hiding this comment.
LGTM
But I doubt this should be backported.
Considering it's a bug that makes the interpreter crash, I think this should. |
Only for debug builds. |
|
Yes, but I still think it's better to backport it since it can be used by third-party libraries (let's discuss it on the issue instead). |
|
Ok, maybe it's better to have a separate PR actually. |
This reverts commit eb15e71.
|
I'm reverting the |
There was a problem hiding this comment.
Yep, this seems correct.
Edit: One nitpick (a slightly smaller diff):
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index 1201fa0949..78fbdcdf77 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -3291,6 +3291,9 @@ itertools_count_impl(PyTypeObject *type, PyObject *long_cnt,
PyErr_Clear();
fast_mode = 0;
}
+ else if (cnt == PY_SSIZE_T_MAX) {
+ fast_mode = 0;
+ }
}
} else {
cnt = 0;|
I think it will be more likely to have cnt equal to maxsize rather than having an error. Which is why I put that test first. |
Well, in terms of probability - it's more likely to have an error (this happens on countable subset of integers), rather having cnt equal to some fixed value ;) |
|
Actually I was wrong. I thought that the error only happened in bad situations but the overflow exception happens when you put something > maxsize so your fix is better! |
|
+1 for backporting |
…e)` (pythonGH-126617) (cherry picked from commit 6e3bb8a) Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
|
GH-126739 is a backport of this pull request to the 3.13 branch. |
|
I don't know what is going on with the 3.12 backport, it seems to be stuck. |
|
Merged, thanks @picnixz for the fix and thanks @devdanzin for the bug report. |
|
GH-126740 is a backport of this pull request to the 3.12 branch. |
itertoolsmodule.c: itertools_count_implforcount(sys.maxsize)#126595