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
integer overflow in itertools.combinations #67555
Comments
# Bug # OS info #
# % ./python -V
# Python 3.4.1
#
# % uname -a
# Linux ubuntu 3.8.0-29-generic #42~precise1-Ubuntu SMP Wed Aug 14 15:31:16 UTC 2013 i686 i686 i386 GNU/Linux
#
import itertools as it
it.combinations("AA", 2**30) |
New changeset 014886dae5c4 by Benjamin Peterson in branch '3.3': New changeset 2f73de7ffcf5 by Benjamin Peterson in branch '3.4': New changeset 886559229911 by Benjamin Peterson in branch 'default': New changeset fe203370c049 by Benjamin Peterson in branch '2.7': |
This commit (and three other) causes compiler warnings: ./Modules/itertoolsmodule.c: In function ‘product_new’:
./Modules/itertoolsmodule.c:2025:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (repeat > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) ||
^
./Modules/itertoolsmodule.c:2026:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
nargs > PY_SSIZE_T_MAX/(repeat * sizeof(Py_ssize_t))) {
^
./Modules/itertoolsmodule.c: In function ‘combinations_new’:
./Modules/itertoolsmodule.c:2371:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
^
./Modules/itertoolsmodule.c: In function ‘cwr_new’:
./Modules/itertoolsmodule.c:2716:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
^
./Modules/itertoolsmodule.c: In function ‘permutations_new’:
./Modules/itertoolsmodule.c:3061:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (n > PY_SSIZE_T_MAX/sizeof(Py_ssize_t) ||
^
./Modules/itertoolsmodule.c:3062:11: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
r > PY_SSIZE_T_MAX/sizeof(Py_ssize_t)) {
^ May be use PyMem_New instead of PyMem_Malloc? |
And with this patch an OverflowError in tests should be replaced with (OverflowError, MemoryError). Updated patch also fixes other bugs in itertools tests. |
lgtm |
New changeset 356ed025dbae by Serhiy Storchaka in branch '3.3': New changeset 98c720c3e061 by Serhiy Storchaka in branch '3.4': New changeset 4cb316fe6bf2 by Serhiy Storchaka in branch 'default': |
New changeset 887526ebb013 by Serhiy Storchaka in branch '2.7': |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: