fuzz: adds validation target for maybe invalid module compilation (#879)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
40
internal/integration_test/fuzz/wazerolib/validate.go
Normal file
40
internal/integration_test/fuzz/wazerolib/validate.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package main
|
||||
|
||||
import "C"
|
||||
import (
|
||||
"context"
|
||||
"reflect"
|
||||
"unsafe"
|
||||
|
||||
"github.com/tetratelabs/wazero"
|
||||
)
|
||||
|
||||
// validate accepts maybe-invalid Wasm module bytes and ensures that our validation phase works correctly
|
||||
// as well as the compiler doesn't panic during compilation!
|
||||
//
|
||||
//export validate
|
||||
func validate(binaryPtr uintptr, binarySize int) {
|
||||
wasmBin := *(*[]byte)(unsafe.Pointer(&reflect.SliceHeader{
|
||||
Data: binaryPtr,
|
||||
Len: binarySize,
|
||||
Cap: binarySize,
|
||||
}))
|
||||
|
||||
failed := true
|
||||
defer func() {
|
||||
if failed {
|
||||
// If the test fails, we save the binary and wat into testdata directory.
|
||||
saveFailedBinary(wasmBin, "", "TestReRunFailedValidateCase")
|
||||
}
|
||||
}()
|
||||
|
||||
tryCompile(wasmBin)
|
||||
failed = false
|
||||
}
|
||||
|
||||
// Ensure that validation and compilation do not panic!
|
||||
func tryCompile(wasmBin []byte) {
|
||||
ctx := context.Background()
|
||||
compiler := wazero.NewRuntimeWithConfig(ctx, wazero.NewRuntimeConfigCompiler())
|
||||
_, _ = compiler.CompileModule(ctx, wasmBin)
|
||||
}
|
||||
Reference in New Issue
Block a user