[转载]搞爆编译器的代码



本文转自:http://blog.csdn.net/gy_jk/archive/2009/10/05/4634241.aspx

作者是本组Online Judge系统Linux评测端技术人员

pascal:

{$inline on}
procedure a; inline;
begin 
end;
procedure b; inline;
begin
        a;a;a;a;a;a;a;a;a;a
end;
procedure c; inline;
begin 
        b;b;b;b;b;b;b;b;b;b
end;
procedure d; inline;
begin 
        c;c;c;c;c;c;c;c;c;c
end;
procedure e; inline;
begin 
        d;d;d;d;d;d;d;d;d;d
end;
procedure f; inline;
begin 
        e;e;e;e;e;e;e;e;e;e
end;
procedure g; inline;
begin 
        f;f;f;f;f;f;f;f;f;f
end;
procedure h; inline;
begin 
        g;g;g;g;g;g;g;g;g;g
end;
procedure i; inline;
begin 
        h;h;h;h;h;h;h;h;h;h
end;
procedure j; inline;
begin 
        i;i;i;i;i;i;i;i;i;i
end;
procedure k; inline;
begin 
        j;j;j;j;j;j;j;j;j;j
end;
begin
        k;k;k;k;k;k;k;k;k;k
end.

C/C++:

#define A(x) x##x
#define B(x) A(x)A(x)
#define C(x) B(B(x))
#define D(x) C(C(x))
#define E(x) D(D(x))
#define F(x) E(E(x))
#define G(x) F(F(x))
#define H(x) G(G(x))
int main()
{
        int H(x) = 0;
}

fpc由于一直没把内存耗完,所以一直没停下来,倒是把系统弄得很慢。

g++把2G内存耗完后就爆了,耗时23s

运行着g++时:

$ free -m
             total       used       free     shared    buffers     cached

Mem:          2023       1975         48          0          1         14
-/+ buffers/cache:       1958         64

Swap:         4102        164       3937

$ time g++ test1.cpp

cc1plus: out of memory allocating 536870912 bytes after a total of 2060288 bytes

real    0m23.594s

user    0m12.542s
sys     0m3.652s

$ time fpc test.pas
Free Pascal Compiler version 2.2.4 [2009/03/28] for i386
Copyright (c) 1993-2008 by Florian Klaempfl
Target OS: Linux for i386

Compiling test.pas
Fatal: Compilation aborted

real    3m36.956s
user    0m0.000s
sys     0m0.034s

这些代码看似无聊,却对OJ系统的安全构成巨大威胁。。 看来要限制编译时间才行。

No comments yet.

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">
TimeZone: GMT.
Except as otherwise noted,all original text and pictures without persons in it are published under the GNU Free Document License, all original codes are published under the Apache License,all photos with persons in it are copyright protected, and all forwarded content is copyrighted by the copyright owner.The owner of the content keeps the permission of changing the publication license
ICP Number for Non-profit Internet Service in PRC is (Sichuan) No.09034160