STINNER Victor added the comment:
Then, on Ubuntu 14.04, 32-bit:
$ python mega_concat.py
Segmentation fault (core dumped)
What is your Python version? It looks like Ubuntu Trusty provides Python 2.7.6.
I'm unable to reproduce the issue on ArchLinux 32-bit with Python 2.7.8. The
issue was
Josh Rosenberg added the comment:
You're supposed to use that code to create a file (the output file is just
+...+).
If you want something that won't MemoryError generating the file, this is a
memory free version of the code to generate the file:
import itertools, sys
New submission from Kevin Dyer:
The following can be used to generate a file called mega_concat.py:
N = 2**17
my_array = []
for i in range(N):
my_array.append(\\)
print '+'.join(my_array)
Then, on Ubuntu 14.04, 32-bit:
$ python mega_concat.py
Segmentation fault (core dumped)
$ python3
Josh Rosenberg added the comment:
It's not out of memory at all. It's (probably) a blown stack during compilation
optimization. Modern Py3 has fixed this by simply preventing silly levels of
literal concatenation like this causing indefinite call stack expansion; the
older ones just allowed
Kevin Dyer added the comment:
Gotcha. Thanks for the explanation.
Two questions:
1) Given that it's probably not an out-of-memory issue, is it possible that
this could turn into something more malicious? (e.g., an arbitrary code
execution vulnerability?)
2) It's not obvious to me why