summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcheck.py2
-rw-r--r--src/wasm-interpreter.h9
2 files changed, 9 insertions, 2 deletions
diff --git a/check.py b/check.py
index e8d63e5e1..979437346 100755
--- a/check.py
+++ b/check.py
@@ -84,7 +84,7 @@ if len(requested) == 0:
# 'address' : filed issue, test looks invalid
# 'exports', 'int_literals' : has a "return" https://github.com/WebAssembly/spec/issues/164
# 'switch': todo once stable
- spec_tests = [os.path.join('spec', t + '.wast') for t in ['conversions', 'endianness', 'f32_cmp', 'f32', 'f64_cmp', 'f64', 'float_exprs', 'forward', 'func_ptrs', 'functions', 'has_feature', 'i32', 'i64', 'imports', 'int_exprs', 'left-to-right', 'memory_redundancy', 'memory_trap', 'names', 'resizing']]
+ spec_tests = [os.path.join('spec', t + '.wast') for t in ['conversions', 'endianness', 'f32_cmp', 'f32', 'f64_cmp', 'f64', 'float_exprs', 'forward', 'func_ptrs', 'functions', 'has_feature', 'i32', 'i64', 'imports', 'int_exprs', 'left-to-right', 'memory_redundancy', 'memory_trap', 'names', 'resizing', 'runaway-recursion']]
else:
spec_tests = requested[:]
diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h
index a935d2069..0e67a1845 100644
--- a/src/wasm-interpreter.h
+++ b/src/wasm-interpreter.h
@@ -26,7 +26,8 @@ int32_t safe_ctz(int32_t v) {
}
enum {
- pageSize = 64*1024
+ pageSize = 64*1024,
+ maxCallDepth = 5000
};
//
@@ -66,6 +67,8 @@ public:
private:
+ size_t callDepth = 0;
+
#ifdef WASM_INTERPRETER_DEBUG
int indent = 0;
#endif
@@ -680,6 +683,9 @@ private:
}
};
+ if (callDepth > maxCallDepth) externalInterface->trap();
+ callDepth++;
+
Function *function = wasm.functionsMap[name];
assert(function);
FunctionScope scope(function, arguments);
@@ -687,6 +693,7 @@ private:
Literal ret = ExpressionRunner(*this, scope).visit(function->body).value;
if (function->result == none) ret = Literal();
assert(function->result == ret.type);
+ callDepth--;
return ret;
}