compiler(amd64),interpreter: signed-extend to 32-bit in V128ExtractLane. (#695)

Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
Takeshi Yoneda
2022-07-14 12:47:44 +09:00
committed by GitHub
parent 7474308111
commit 48d6e6f2e1
7 changed files with 76 additions and 3 deletions

View File

@@ -0,0 +1,2 @@
Here we collect the test cases found by [wazero-fuzz](https://github.com/tetratelabs/wazero-fuzz).
The test data in `./testdata` directory is named as `12345.wat` where the numebr corresponds to the PR or issue in this repostiroy.

View File

@@ -0,0 +1,54 @@
package fuzzcases
import (
"context"
_ "embed"
"testing"
"github.com/tetratelabs/wazero"
"github.com/tetratelabs/wazero/internal/platform"
"github.com/tetratelabs/wazero/internal/testing/require"
)
var ctx = context.Background()
var (
//go:embed testdata/695.wasm
case695 []byte
)
func newRuntimeCompiler() wazero.Runtime {
return wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfigCompiler().WithWasmCore2())
}
func newRuntimeInterpreter() wazero.Runtime {
return wazero.NewRuntimeWithConfig(wazero.NewRuntimeConfigInterpreter().WithWasmCore2())
}
// Test695 requires two functions to exit with "out of bounds memory access" consistently across the implementations.
func Test695(t *testing.T) {
if !platform.CompilerSupported() {
return
}
for _, tc := range []struct {
name string
r wazero.Runtime
}{
{name: "compiler", r: newRuntimeCompiler()},
{name: "interpreter", r: newRuntimeInterpreter()},
} {
tc := tc
t.Run(tc.name, func(t *testing.T) {
defer tc.r.Close(ctx)
module, err := tc.r.InstantiateModuleFromBinary(ctx, case695)
require.NoError(t, err)
_, err = module.ExportedFunction("i8x16s").Call(ctx)
require.Contains(t, err.Error(), "out of bounds memory access")
_, err = module.ExportedFunction("i16x8s").Call(ctx)
require.Contains(t, err.Error(), "out of bounds memory access")
})
}
}

Binary file not shown.

View File

@@ -0,0 +1,16 @@
(module
(type (func))
(func (export "i8x16s") (type 0)
v128.const i8x16 0x0 0xff 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0 0x0
i8x16.extract_lane_s 1 ;; uint32(int8(0xff)) = 0xffff_ffff
;; if the signed extend is 64-bit, then the offset 0xffff_ffff_ffff_ffff + 1= 0 and not result in out of bounds.
v128.load32_zero offset=1 align=1
unreachable)
(func (export "i16x8s") (type 0)
v128.const i16x8 0x0 0xffff 0x0 0x0 0x0 0x0 0x0 0x0
i16x8.extract_lane_s 1 ;; uint32(int16(0xffff)) = 0xffff_ffff
;; if the signed extend is 64-bit, then the offset 0xffff_ffff_ffff_ffff + 1= 0 and not result in out of bounds.
v128.load32_zero offset=1 align=1
unreachable)
(memory 1 1)
)