This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author pkt
Recipients pkt
Date 2015-02-01.13:54:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1422798853.28.0.166749700091.issue23363@psf.upfronthosting.co.za>
In-reply-to
Content
# Bug
# ---
# 
# static PyObject *
# permutations_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
# {
#     ...
# 1   cycles = PyMem_Malloc(r * sizeof(Py_ssize_t));
#     ...
#     for (i=0 ; i<r ; i++)
# 2       cycles[i] = n - i;
# 
# 1. if r=2^30, then r*sizeof(Py_ssize_t)=2^30*2^2=0 (modulo 2^32), so malloc
#    allocates a 0 byte buffer
# 2. r=2^30>0, so we write well beyond the buffer's end
# 
# Crash
# -----
# 
# Breakpoint 1, permutations_new (type=0x83394e0 <permutations_type>, args=('A', 1073741824), kwds=0x0) at ./Modules/itertoolsmodule.c:3012
# ...
# 3044        indices = PyMem_Malloc(n * sizeof(Py_ssize_t));
# (gdb) print r
# $2 = 1073741824
# (gdb) print r*4
# $3 = 0
# (gdb) c
# Continuing.
#  
# Program received signal SIGSEGV, Segmentation fault.
# 0x08230900 in permutations_new (type=0x83394e0 <permutations_type>, args=('A', 1073741824), kwds=0x0) at ./Modules/itertoolsmodule.c:3054
# 3054            cycles[i] = n - i;
# 
# 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.permutations("A", 2**30)
History
Date User Action Args
2015-02-01 13:54:13pktsetrecipients: + pkt
2015-02-01 13:54:13pktsetmessageid: <1422798853.28.0.166749700091.issue23363@psf.upfronthosting.co.za>
2015-02-01 13:54:13pktlinkissue23363 messages
2015-02-01 13:54:13pktcreate