]> granicus.if.org Git - python/commitdiff
don't scale compiler stack frames if the recursion limit is huge (closes #19098)
authorBenjamin Peterson <benjamin@python.org>
Fri, 27 Sep 2013 02:17:45 +0000 (22:17 -0400)
committerBenjamin Peterson <benjamin@python.org>
Fri, 27 Sep 2013 02:17:45 +0000 (22:17 -0400)
Misc/NEWS
Python/symtable.c

index 3b232f2138eb0701ebeeb1cb69b26a48e1222c5c..e7910f3365f09f535aaff583c140f4606228027d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -12,6 +12,9 @@ What's New in Python 3.3.3 release candidate 1?
 Core and Builtins
 -----------------
 
+- Issue #19098: Prevent overflow in the compiler when the recursion limit is set
+  absurbly high.
+
 - Issue #18942: sys._debugmallocstats() output was damaged on Windows.
 
 - Issue #18667: Add missing "HAVE_FCHOWNAT" symbol to posix._have_functions.
index 48495f72a28fe858b6074a3b24427140c4df747d..1e13b790de3d01e7d8702b579620cca02a6a954d 100644 (file)
@@ -239,6 +239,7 @@ PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
     asdl_seq *seq;
     int i;
     PyThreadState *tstate;
+    int recursion_limit = Py_GetRecursionLimit();
 
     if (st == NULL)
         return st;
@@ -251,8 +252,11 @@ PySymtable_Build(mod_ty mod, const char *filename, PyFutureFeatures *future)
         PySymtable_Free(st);
         return NULL;
     }
-    st->recursion_depth = tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE;
-    st->recursion_limit = Py_GetRecursionLimit() * COMPILER_STACK_FRAME_SCALE;
+    /* Be careful here to prevent overflow. */
+    st->recursion_depth = (tstate->recursion_depth < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
+        tstate->recursion_depth * COMPILER_STACK_FRAME_SCALE : tstate->recursion_depth;
+    st->recursion_limit = (recursion_limit < INT_MAX / COMPILER_STACK_FRAME_SCALE) ?
+        recursion_limit * COMPILER_STACK_FRAME_SCALE : recursion_limit;
 
     /* Make the initial symbol information gathering pass */
     if (!GET_IDENTIFIER(top) ||