File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -914,10 +914,28 @@ def test_dangerous_builtins_cannot_be_reintroduced(self):
914914 # ==================== RESOURCE LIMITS ====================
915915
916916 def test_deep_nesting_is_rejected (self ):
917+ """Over-deep results raise a clear error rather than recursing.
918+
919+ Python 3.8's parser rejects very deep literals with SyntaxError before
920+ the evaluator ever runs, and its exact threshold differs from later
921+ versions, so both outcomes are acceptable: the point is that a deeply
922+ nested literal never reaches the caller.
923+ """
917924 expr = "[" * 150 + "]" * 150
918- with self .assertRaises ((RuntimeError , SyntaxError )):
925+ with self .assertRaises ((RuntimeError , SyntaxError , RecursionError )):
919926 safe_eval (expr , allow_objects = True )
920927
928+ def test_deeply_nested_via_variables_is_bounded (self ):
929+ """Depth is also bounded for nesting the parser never sees."""
930+ deep = []
931+ node = deep
932+ for _ in range (150 ):
933+ child = []
934+ node .append (child )
935+ node = child
936+ with self .assertRaises (RuntimeError ):
937+ safe_eval ("o" , allowed_vars = {"o" : deep }, allow_objects = True )
938+
921939 def test_timeout_still_enforced_and_process_reaped (self ):
922940 with self .assertRaises (EvaluationTimeoutError ):
923941 safe_eval ("f()" , allowed_vars = {"f" : _busy_forever },
You can’t perform that action at this time.
0 commit comments