Skip to content

Commit

Permalink
Limit max recursion depth by default. Fixes IronLanguages#1192 (...)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuno Meyer committed May 9, 2015
1 parent 31f5c88 commit 29d0b73
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Languages/IronPython/IronPython/Runtime/PythonOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,10 @@ public PythonOptions(IDictionary<string, object> options)
_optimize = GetOption(options, "Optimize", false);
_stripDocStrings = GetOption(options, "StripDocStrings", false);
_division = GetOption(options, "DivisionOptions", PythonDivisionOptions.Old);
_recursionLimit = GetOption(options, "RecursionLimit", Int32.MaxValue);
_recursionLimit = GetOption(options, "RecursionLimit", 2000);
// CPython has 1000 as default recursion limit, which is reported (e.g. www.stackoverflow.com) to be somewhat
// conservative. Not limiting recursion on the other hand obfuscates user code issues and the
// resulting StackOverflowException be interpreted as an interpreter bug.
_indentationInconsistencySeverity = GetOption(options, "IndentationInconsistencySeverity", Severity.Ignore);
_enableProfiler = GetOption(options, "EnableProfiler", false);
_lightweightScopes = GetOption(options, "LightweightScopes", false);
Expand Down
28 changes: 28 additions & 0 deletions Languages/IronPython/Tests/test_sys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
#####################################################################################
#
# Copyright (c) Microsoft Corporation. All rights reserved.
#
# This source code is subject to terms and conditions of the Apache License, Version 2.0. A
# copy of the license can be found in the License.html file at the root of this distribution. If
# you cannot locate the Apache License, Version 2.0, please send an email to
# [email protected]. By using this source code in any fashion, you are agreeing to be bound
# by the terms of the Apache License, Version 2.0.
#
# You must not remove this notice, or any other, from this software.
#
#
#####################################################################################

##
## Test builtin sys module
##

import sys
from iptest.assert_util import *

def test_recursionlimit_default():
# we don't care the exact value, but recursion should be limited by default
Assert(sys.getrecursionlimit() < 10000)

run_test(__name__)
11 changes: 11 additions & 0 deletions Test/IronPython.tests
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,17 @@
<NotParallelSafe>false</NotParallelSafe>
<WorkingDirectory>%DLR_ROOT%\Languages\IronPython\Tests</WorkingDirectory>
</Test>
<Test>
<Name>test_sys_20</Name>
<Filename>%DLR_ROOT%\Languages\IronPython\Internal\ipy.bat</Filename>
<Arguments>test_sys.py</Arguments>
<MaxDuration>600000</MaxDuration>
<LongRunning>false</LongRunning>
<Disabled>false</Disabled>
<RequiresAdmin>false</RequiresAdmin>
<NotParallelSafe>false</NotParallelSafe>
<WorkingDirectory>%DLR_ROOT%\Languages\IronPython\Tests</WorkingDirectory>
</Test>
<Test>
<Name>test_tuple_20</Name>
<Filename>%DLR_ROOT%\Languages\IronPython\Internal\ipy.bat</Filename>
Expand Down

0 comments on commit 29d0b73

Please sign in to comment.