viff

changeset 1275:b01d3537960d

Limit the recursion depth.
author Marcel Keller <mkeller@cs.au.dk>
date Fri, 09 Oct 2009 16:27:59 +0200
parents 31da6944a413
children f9ab0f24979d
files viff/runtime.py
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line diff
     1.1 --- a/viff/runtime.py	Fri Oct 09 11:02:05 2009 +0200
     1.2 +++ b/viff/runtime.py	Fri Oct 09 16:27:59 2009 +0200
     1.3 @@ -38,6 +38,7 @@
     1.4  from optparse import OptionParser, OptionGroup
     1.5  from collections import deque
     1.6  import os
     1.7 +import sys
     1.8  
     1.9  from viff.field import GF256, FieldElement
    1.10  from viff.util import wrapper, rand, deep_wait, track_memory_usage, begin, end
    1.11 @@ -605,6 +606,8 @@
    1.12          #: Record the recursion depth.
    1.13          self.depth_counter = 0
    1.14          self.max_depth = 0
    1.15 +        #: Recursion depth limit by experiment, including security margin.
    1.16 +        self.depth_limit = int(sys.getrecursionlimit() / 50)
    1.17          #: Use deferred queues only if the ViffReactor is running.
    1.18          self.using_viff_reactor = isinstance(reactor, viff.reactor.ViffReactor)
    1.19  
    1.20 @@ -921,8 +924,11 @@
    1.21              if self.depth_counter > self.max_depth:
    1.22                  # Record the maximal depth reached.
    1.23                  self.max_depth = self.depth_counter
    1.24 +                if self.depth_counter >= self.depth_limit:
    1.25 +                    print "Recursion depth limit reached."
    1.26  
    1.27 -            reactor.doIteration(0)
    1.28 +            if self.depth_counter < self.depth_limit:
    1.29 +                reactor.doIteration(0)
    1.30  
    1.31              self.depth_counter -= 1
    1.32              self.activation_counter = 0