Hot answers tagged

224

Python import sys sys.setrecursionlimit(1) This will cause the interpreter to fail immediately: $ cat test.py import sys sys.setrecursionlimit(1) $ python test.py Exception RuntimeError: 'maximum recursion depth exceeded' in <function _remove at 0x10e947b18> ignored Exception RuntimeError: 'maximum recursion depth exceeded' in <function _remove ...


189

Python import webbrowser webbrowser.open("http://stackoverflow.com/")


131

C / Linux 32bit void g(void *p){ void *a[1]; a[2]=p-5; } void f(){ void *a[1]; g(a[2]); } main(){ f(); return 0; } Works by overwriting the return address, So g returns to the point in main before calling f. Will work for any platform where return addresses are on the stack, but may require tweaks. Of course,...


108

JavaScript / DOM with (document.body) { addEventListener('DOMSubtreeModified', function() { appendChild(firstChild); }, false); title = 'Kill me!'; } If you want to kill your browser try that out in the console.


91

Java Saw something like this somewhere around here: Edit: Found where I saw it: Joe K's answer to Shortest program that throws StackOverflow Error public class A { String val; public String toString() { return val + this; } public static void main(String[] args) { System.out.println(new A()); } } That can confuse some ...


77

C Quite easy: int main() { int large[10000000] = {0}; return 0; }


63

Non-recursive stack overflow in C Calling convention mismatch. typedef void __stdcall (* ptr) (int); void __cdecl hello (int x) { } void main () { ptr goodbye = (ptr)&hello; while (1) goodbye(0); } Compile with gcc -O0. __cdecl functions expect the caller to clean up the stack, and __stdcall expects the callee to do it, so by calling ...


62

I was frustrated by the fact that java 7 and java 8 are immune to my evil code in my previous answer. So I decided that a patch for that was necessary. Success! I made printStackTrace() throw a StackOverflowError. printStackTrace() is commonly used for debugging and logging and no one reasonably suspects that it could be dangerous. It is not hard to see ...


62

JavaScript window.toString = String.toLocaleString; +this;


59

Brain-Flak Classic, 1271 1247 1239 bytes <>(()){<>((([][][][][])<(((({}){})(({})({}))[])({}(({})({}({})({}{}(<>)))))[])>{()<{}>}{})<{{}}{}>())}{}<>(<(({()(((<>))<>)}{}{<({}(([][][])((({})({}))[]{})){})>((){[]<({}{})((){[]<({}{}<>((({})({})){}{}){})(<>)>}{}){{}{}<>(<(...


57

Linux x86 NASM Assembly section .data helloStr: db 'Hello world!',10 ; Define our string helloStrLen: equ $-helloStr ; Define the length of our string section .text global _start doExit: mov eax,1 ; Exit is syscall 1 mov ebx,0 ; Exit status for success int 80h ; Execute syscall printHello: ...


48

C++ at compile time template <unsigned N> struct S : S<N-1> {}; template <> struct S<0> {}; template struct S<-1>; $ g++ -c test.cc -ftemplate-depth=40000 g++: internal compiler error: Segmentation fault (program cc1plus) Please submit a full bug report, with preprocessed source if appropriate. See for instructions. There ...


45

Bash (Danger Alert) while true do mkdir x cd x done Strictly speaking, that will not directly stack overflow, but generates what may be labelled as "a persistent stack-over-flow generating situation": when you run this until your disk is full, and want to remove the mess with "rm -rf x", that one is hit. It does not happen on all systems, though. ...


43

Java A nice one from Java Puzzlers. What does it print? public class Reluctant { private Reluctant internalInstance = new Reluctant(); public Reluctant() throws Exception { throw new Exception("I'm not coming out"); } public static void main(String[] args) { try { Reluctant b = new Reluctant(); ...


41

LaTeX \end\end The input stack overflows because \end repeatedly expands itself in an infinite loop, as explained here. TeX fails with a TeX capacity exceeded, sorry [input stack size=5000] or similar.


40

BF Will eventually overflow the stack, just depends how long the interpreter makes the stack... +[>+]


32

On the Internet (used by billion people/day) Redirects, HTTP status code: 301 For example, on the Dell support website (no offense, sorry Dell): If you remove the support TAG from the URL then it goes into infinite redirects. In the following URL, ###### is any support TAG. http://www.dell.com/support/drivers/uk/en/ukdhs1/ServiceTag/######?s=BSD&~...


32

C#, at compile time There are a number of ways to cause the Microsoft C# compiler to blow its stack; any time you see an "expression is too complex to compile" error from the C# compiler that is almost certainly because the stack has blown. The parser is recursive descent, so any sufficiently deeply nested language structures will blow the stack: class C ...


31

PHP A stackoverflow done with looping elements only. $a = array(&$a); while (1) { foreach ($a as &$tmp) { $tmp = array($tmp, &$a); } } Explanation (hover to see the spoiler):


30

Java I did the exact opposite – a program that should obviously throw a stack overflow error, but doesn't. public class Evil { public static void main(String[] args) { recurse(); } private static void recurse() { try { recurse(); } finally { recurse(); } } } Hint: the program runs in ...


30

C# First post, so please go easy on me. class Program { static void Main() { new System.Diagnostics.StackTrace().GetFrame(0).GetMethod().Invoke(null, null); } } This simply creates a stack trace, grabs the top frame (which will be our last call to Main()), gets the method, and invokes it.


26

Java In Java 5, printStackTrace() enters an infinite loop. In Java 6, printStackTrace() throws StackOverflowError. In Java 7 and 8, it was fixed. The crazy thing is that in Java 5 and 6, it does not comes from user code, it happens in JDK's code. No one reasonable suspects that printStackTrace() can be dangerous to execute. public class Bad { public ...


19

MATL, 6 bytes "@?@}x Input is a row vector of numbers. The final stack is shown upside down, with the most recent element below. Try it online! Or verify all test cases. Explanation " % For each element in the input (implicit) @ % Push current element ? % If non-zero (this consumes the current element) @ % Push ...


17

JavaScript: Non-recursive, iterative function mutation var f = function() { console.log(arguments.length); }; while (true) { f = f.bind(null, 1); f(); } There's no recursion here at all. f will be repeatedly curried with more and more arguments until it can overflow the stack in a single function call. The console.log part is optional in case ...


17

Retina, 167 165 157 150 123 bytes This totally looks like a challenge that should be solved with a single regex... (despite the header saying "Retina", this is just a vanilla .NET regex, matching valid inputs). ^(?=\D*((?=(?<3>1+))1)+)((?=A(?<1-3>.+)|B(?<1-4>.+)|C(?<1-5>.+)).(?=A.*(?!\3)(\1)|B.*(?!\4)(\1)|C.*(?!\5)(\1)).)+(?!\3|\4)1 ...


16

Python 2, 59394 59244 58534 58416 58394 58250 Ok here is my solution. import re import math cache = {0:"<()>"} def find(x,i,j): return i*((x**2+x)/2)+(j+1)*((x**2-x)/2) def solve(x, i, j): a = (i + j + 1)/2. b = (i - j - 1)/2. c = -x return (-b + math.sqrt(b**2 - 4*a*c))/(2*a) def size(i,j=0): return 4*(i+j)+14 def ...


14

Ruby, 67 lines of regex substitutions I decided to write the interpreter in regex, while sticking to efficient algorithms. I could have gone for plain bytes, but using symbols makes the code more readable in my opinion. Of course, if we could pack two instructions in one byte... Concatenation of negative values results in ten's complement behavior, ...


14

C# with an epic fail using System.Xml.Serialization; [XmlRoot] public class P { public P X { get { return new P(); } set { } } static void Main() { new XmlSerializer(typeof(P)).Serialize(System.Console.Out, new P()); } } The way it fails is epic, it blew my mind completely: It is just one frame of a seemingly infinite tripping ...


14

Java "only" 311 272 263 261 260 259 256 bytes Saved 39 countless bytes due to @Frozn noticing an older debug feature as well as some clever golfing tricks. Golfed version int i(int n,int[]m){int j=0,k=0,i=n;Stack<Integer>t,s[]=new Stack[3];for(;j<3;)s[j++]=new Stack();for(;i-->0;)s[0].push(i);for(;k<m.length;k+=2)if((t=s[m[k+1]]).size()>...


13

bash _(){ _;};_ While many might recognize that the recursion is obvious, but it seems pretty. No? Upon execution, you are guaranteed to see: Segmentation fault (core dumped)


Only top voted, non community-wiki answers of a minimum length are eligible