-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-126595: fix a crash when calling itertools.count(sys.maxsize)
#126617
gh-126595: fix a crash when calling itertools.count(sys.maxsize)
#126617
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
+1 for backporting |
…e)` (pythonGH-126617) (cherry picked from commit 6e3bb8a) Co-authored-by: Bénédikt Tran <[email protected]>
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_impl
forcount(sys.maxsize)
#126595