

Blowing Python's stack with excessive recursion
source link: http://rachelbythebay.com/w/2011/10/01/pystack/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Blowing Python's stack with excessive recursion
This is kind of fun:
$ Z=52372; echo '#!/usr/bin/env python' > crash2.py; for i in `seq 1 $Z`; do echo "if None: pass"; done >> crash2.py ; chmod a+rx crash2.py ; ./crash2.py
$
Nothing happens, right? But, just add one more "if", and...
$ Z=52373; echo '#!/usr/bin/env python' > crash2.py; for i in `seq 1 $Z`; do echo "if None: pass"; done >> crash2.py ; chmod a+rx crash2.py ; ./crash2.py
Segmentation fault
Kaboom! gdb says Python blows up in Python/compile.c with stackdepth_walk() calling itself seemingly forever.
What this means is with the default 8192K stack and this particular assortment of config details on my system, it blows the stack after 52,372 if blocks.
This came up when a friend was trying to benchmark something by just adding a whole bunch of calls to something to his code. It blew up spectacularly, leading to our investigation and this finding.
Not surprisingly, something that does a recursive function call ran out of stack space after an excessive number of calls. Such is life.
Recommend
-
53
-
31
README.md Third Party Web This document is a summary of which third party scripts are most responsible for excessive JavaScript execution on the web to...
-
15
Rogue Key Attack on Genanro DKG for Polynomials of Excessive Degree Rogue Key Attack on Gennaro et al. DKG for Polynomials of Excessive Degree TL;DR Distributed Key Generation (DKG) is a protocol used to crea...
-
16
Tail Recursion In Python by Chris Penner Jul 26, 2016
-
6
Recursion in Python: An Introduction by
-
8
Python maximum recursion depth exceeded in comparison Sep 4 Originally published at
-
6
A Simple Recursion Tree Visualizer for PythonOne programming paradigm, that is hardest to visualize, as almost every single programmer out there will agree on, is Recur...
-
2
How to debug stack frames and recursion in GDB Skip to main content ...
-
6
Most complex tasks in Python can be broken down into simpler subtasks. Recursion helps to achieve this, hence making the code clean and neat. This tutorial will introduce recursion, the benefits of recursion, and how to use it in Python programmin...
-
9
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK