From 44f23e2643a1a34e1b5987231285ad57cdc6f334 Mon Sep 17 00:00:00 2001 From: Takeshi Yoneda Date: Fri, 13 Oct 2023 10:37:11 +0900 Subject: [PATCH] fuzz: allows compiler=stackoverflow,intp=unreachable (#1779) Signed-off-by: Takeshi Yoneda --- internal/engine/wazevo/wazevoapi/debug_options.go | 6 +++++- .../integration_test/fuzz/fuzz/fuzz_targets/wazero_abi.rs | 2 -- internal/integration_test/fuzz/wazerolib/nodiff.go | 6 ++++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/internal/engine/wazevo/wazevoapi/debug_options.go b/internal/engine/wazevo/wazevoapi/debug_options.go index 69e9909a..a846a6e2 100644 --- a/internal/engine/wazevo/wazevoapi/debug_options.go +++ b/internal/engine/wazevo/wazevoapi/debug_options.go @@ -60,7 +60,11 @@ const ( func CheckStackGuardPage(s []byte) { for i := 0; i < StackGuardCheckGuardPageSize; i++ { if s[i] != 0 { - panic(fmt.Sprintf("BUG: stack guard page is corrupted: %s", hex.EncodeToString(s[:StackGuardCheckGuardPageSize]))) + panic( + fmt.Sprintf("BUG: stack guard page is corrupted:\n\tguard_page=%s\n\tstack=%s", + hex.EncodeToString(s[:StackGuardCheckGuardPageSize]), + hex.EncodeToString(s[StackGuardCheckGuardPageSize:]), + )) } } } diff --git a/internal/integration_test/fuzz/fuzz/fuzz_targets/wazero_abi.rs b/internal/integration_test/fuzz/fuzz/fuzz_targets/wazero_abi.rs index f4ec42f1..8314f79a 100644 --- a/internal/integration_test/fuzz/fuzz/fuzz_targets/wazero_abi.rs +++ b/internal/integration_test/fuzz/fuzz/fuzz_targets/wazero_abi.rs @@ -1,7 +1,5 @@ //! This module provides the functions implemented by wazero via CGo. -use wasm_smith::SwarmConfig; - extern "C" { // require_no_diff is implemented in Go, and accepts the pointer to the binary and its size. #[allow(dead_code)] diff --git a/internal/integration_test/fuzz/wazerolib/nodiff.go b/internal/integration_test/fuzz/wazerolib/nodiff.go index c404038f..813dc7f2 100644 --- a/internal/integration_test/fuzz/wazerolib/nodiff.go +++ b/internal/integration_test/fuzz/wazerolib/nodiff.go @@ -314,6 +314,12 @@ func ensureInvocationError(compilerErr, interpErr error) error { interpErrMsg = interpErrMsg[:strings.Index(interpErrMsg, "\n")] } + if strings.Contains(compilerErrMsg, "stack overflow") && strings.Contains(interpErrMsg, "unreachable") { + // Compiler is more likely to reach stack overflow than interpreter, so we allow this case. This case is most likely + // that interpreter reached the unreachable out of "fuel". + return nil + } + if compilerErrMsg != interpErrMsg { return fmt.Errorf("error mismatch:\n\tinterpreter: %v\n\tcompiler: %v", interpErr, compilerErr) }