From b0af95200a37d76eccf285dcb45b4ed6162212d0 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Mon, 12 Apr 2021 18:37:48 -0700 Subject: Fuzzer: Distinguish traps from host limitations (#3801) Host limitations are arbitrary and can be modified by optimizations, so ignore them. For example, if the optimizer removes allocations then a host limit on an allocation error may vanish. Or, an optimization that removes recursion and replaces it with a loop may avoid a host limit on call depth (that is not done currently, but might some day). This removes a class of annoying false positives in the fuzzer. --- src/wasm-interpreter.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/wasm-interpreter.h') diff --git a/src/wasm-interpreter.h b/src/wasm-interpreter.h index d76f3fabf..37bebdf6b 100644 --- a/src/wasm-interpreter.h +++ b/src/wasm-interpreter.h @@ -197,7 +197,7 @@ public: Flow visit(Expression* curr) { depth++; if (maxDepth != NO_LIMIT && depth > maxDepth) { - trap("interpreter recursion limit"); + hostLimit("interpreter recursion limit"); } auto ret = OverriddenVisitor::visit(curr); if (!ret.breaking()) { @@ -1622,7 +1622,7 @@ public: // limits on 32-bit machines, and in particular on wasm32 VMs that do not // have 4GB support, so give up there. if (num >= (1 << 30) / sizeof(Literal)) { - trap("allocation failure"); + hostLimit("allocation failure"); } Literals data(num); if (curr->isWithDefault()) { @@ -1739,6 +1739,8 @@ public: virtual void trap(const char* why) { WASM_UNREACHABLE("unimp"); } + virtual void hostLimit(const char* why) { WASM_UNREACHABLE("unimp"); } + virtual void throwException(const WasmException& exn) { WASM_UNREACHABLE("unimp"); } @@ -2024,6 +2026,8 @@ public: void trap(const char* why) override { throw NonconstantException(); } + void hostLimit(const char* why) override { throw NonconstantException(); } + virtual void throwException(const WasmException& exn) override { throw NonconstantException(); } @@ -2076,6 +2080,7 @@ public: SubType& instance) = 0; virtual bool growMemory(Address oldSize, Address newSize) = 0; virtual void trap(const char* why) = 0; + virtual void hostLimit(const char* why) = 0; virtual void throwException(const WasmException& exn) = 0; // the default impls for load and store switch on the sizes. you can either @@ -3095,6 +3100,10 @@ private: instance.externalInterface->trap(why); } + void hostLimit(const char* why) override { + instance.externalInterface->hostLimit(why); + } + void throwException(const WasmException& exn) override { instance.externalInterface->throwException(exn); } -- cgit v1.2.3