From 9156a64ecad0d8e934ba0b70da148977feab8fde Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 3 Jun 2019 12:05:51 -0700 Subject: [PATCH] add a recursion limit for the interpreter's expression runner as well, not just for tracking wasm calls. this is an internal limit of the interpreter, until we un-recursify it, which may make sense at some point (but it's unlikely interpreting massively-recursive things will be beneficial in the optimizer anyhow - if it could do something with them, it could also do so on the smaller pieces iteratively. this should fix the current recusion issue on the mac bot --- src/wasm-interpreter.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index 85a50163a19..7dd9688c3c3 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -45,7 +45,7 @@ using namespace cashew; extern Name WASM, RETURN_FLOW; -enum { maxCallDepth = 250 }; +enum { maxInterpreterDepth = 250 }; // Stuff that flows around during executing expressions: a literal, or a change // in control flow. @@ -128,8 +128,16 @@ class Indenter { // Execute an expression template class ExpressionRunner : public OverriddenVisitor { +protected: + // Keep a record of call depth, to guard against excessive recursion. + size_t depth = 0; + public: Flow visit(Expression* curr) { + depth++; + if (depth > maxInterpreterDepth) { + trap("interpreter recursion limit"); + } auto ret = OverriddenVisitor::visit(curr); if (!ret.breaking() && (isConcreteType(curr->type) || isConcreteType(ret.value.type))) { @@ -142,6 +150,7 @@ class ExpressionRunner : public OverriddenVisitor { #endif assert(ret.value.type == curr->type); } + depth--; return ret; } @@ -1790,7 +1799,7 @@ template class ModuleInstanceBase { // Internal function call. Must be public so that callTable implementations // can use it (refactor?) Literal callFunctionInternal(Name name, const LiteralList& arguments) { - if (callDepth > maxCallDepth) { + if (callDepth > maxInterpreterDepth) { externalInterface->trap("stack limit"); } auto previousCallDepth = callDepth;