Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.028 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'subject:Python': 0.06; 'cc:addr:python-list': 0.11; 'python': 0.11; 'def': 0.12; 'foo()': 0.16; 'foo(object):': 0.16; 'iterator': 0.16; 'prevent': 0.16; 'machine': 0.22; 'memory': 0.22; 'example': 0.22; 'cc:addr:gmail.com': 0.22; 'cc:addr:python.org': 0.22; '(or': 0.24; 'header:In-Reply-To:1': 0.27; 'raise': 0.29; 'cc:2**2': 0.30; 'forgot': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; "skip:' 10": 0.31; 'agreed.': 0.31; 'subject:programs': 0.31; 'class': 0.32; 'run': 0.32; 'protection.': 0.33; 'skip:_ 10': 0.34; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'should': 0.36; 'bringing': 0.38; '8bit%:6': 0.40; 'eventually': 0.60; 'subject:online': 0.61; 'simple': 0.61; 'physical': 0.72; 'honest': 0.78; 'mistake': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=gOz0Y1ERrwZaVoDAjF2nUrNNrW/qXWiyrPkZGAPaHCA=; b=FUJBjJKY8+OSr+v9POTSHHJbzUPMN3/vmcyM4GJkpNQU9n4qAGfNd2OUHPAmZ9bqe4 Fl5QEEYZL7t5l9/YTUWjrSBTxWOiAdHhKlHtLSbc/qKLV3zC7JJF70AKKFmljPuAAk3R Fvl3m4sZAHZFp5ncjperlD1kIkOUbhSBH0r5YQHqzbYcsFLppTNBE/qeFML0+ef9+HQP P5MTD8J8OS/7SWRfrE1A9o2ZKiCntrkBJWrtsOxlpB54wijSEpIKNpo2wHFyFFQO3m48 /HBN9FBmCwVDoGOBNy/gKSUSLHm5cq7DgvG8wcg+wpMfaDje5r4XEKL3ZZwbP4s2m7pE 5HMw== MIME-Version: 1.0 X-Received: by 10.58.134.16 with SMTP id pg16mr2757323veb.21.1379957529070; Mon, 23 Sep 2013 10:32:09 -0700 (PDT) In-Reply-To: <52404006.1000801@nedbatchelder.com> References: <52404006.1000801@nedbatchelder.com> Date: Mon, 23 Sep 2013 11:32:08 -0600 Subject: Re: building an online judge to evaluate Python programs From: Modulok To: Ned Batchelder Content-Type: multipart/alternative; boundary=089e012949205355db04e710664d Cc: Python mailing list , Dave Angel X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 63 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1379957537 news.xs4all.nl 15902 [2001:888:2000:d::a6]:55345 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:54654 --089e012949205355db04e710664d Content-Type: text/plain; charset=ISO-8859-1 > > > If you want to run untrusted Python code and prevent malice (or stupidity) > from harming you, you need OS-level protection. > > Agreed. Just for fun here's a simple example of what could be an honest mistake that consumes all physical memory and swap. A well behaved kernel will kill the process eventually when it can no longer allocate memory, but not before bringing the machine to its knees: class Foo(object): def __init__(self): self.x = 1 def __iter__(self): return self def next(self): self.x += 1 # Oops. In a well behaved iterator this should eventually # raise 'StopIteration'. I knew I forgot something. a = Foo() b = list(a) -Modulok- --089e012949205355db04e710664d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable

=
If you want to run untrusted Python code and prevent malice (or stupidity) from harming you, you need OS-level protection.


Agreed. Just for fun here's a simple example of what co= uld be an honest mistake
that consumes all physical memory and swap. A well behaved kernel will= kill the
process eventually when it can no longer allocate memor= y, but not before
bringing the machine to its knees:

=A0 =A0 class Foo(object):
=A0 =A0 =A0 =A0 def __i= nit__(self):
=A0 =A0 =A0 =A0 =A0 =A0 self.x =3D 1
=A0 = =A0 =A0 =A0 def __iter__(self):
=A0 =A0 =A0 =A0 =A0 =A0 return se= lf
=A0 =A0 =A0 =A0 def next(self):
=A0 =A0 =A0 =A0 =A0 =A0 self.x +=3D 1
=A0 =A0 =A0 =A0 =A0 =A0 # O= ops. In a well behaved iterator this should eventually
=A0 =A0 = =A0 =A0 =A0 =A0 # raise 'StopIteration'. I knew I forgot something.=


=A0 =A0 a =3D Foo()
=A0 =A0 b =3D list(a)


-Modulok-
--089e012949205355db04e710664d--