interpreter: signed-extend to 32-bit in SignExtend32 (#701)
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
This commit is contained in:
@@ -1785,11 +1785,11 @@ func (ce *callEngine) callNativeFunc(ctx context.Context, callCtx *wasm.CallCont
|
||||
}
|
||||
frame.pc++
|
||||
case wazeroir.OperationKindSignExtend32From8:
|
||||
v := int32(int8(ce.popValue()))
|
||||
v := uint32(int8(ce.popValue()))
|
||||
ce.pushValue(uint64(v))
|
||||
frame.pc++
|
||||
case wazeroir.OperationKindSignExtend32From16:
|
||||
v := int32(int16(ce.popValue()))
|
||||
v := uint32(int16(ce.popValue()))
|
||||
ce.pushValue(uint64(v))
|
||||
frame.pc++
|
||||
case wazeroir.OperationKindSignExtend64From8:
|
||||
|
||||
@@ -19,6 +19,8 @@ var (
|
||||
case696 []byte
|
||||
//go:embed testdata/699.wasm
|
||||
case699 []byte
|
||||
//go:embed testdata/701.wasm
|
||||
case701 []byte
|
||||
)
|
||||
|
||||
func newRuntimeCompiler() wazero.Runtime {
|
||||
@@ -112,3 +114,31 @@ func Test699(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Test701 requires two functions to exit with "out of bounds memory access" consistently across the implementations.
|
||||
func Test701(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, case701)
|
||||
require.NoError(t, err)
|
||||
|
||||
_, err = module.ExportedFunction("i32.extend16_s").Call(ctx)
|
||||
require.Contains(t, err.Error(), "out of bounds memory access")
|
||||
|
||||
_, err = module.ExportedFunction("i32.extend8_s").Call(ctx)
|
||||
require.Contains(t, err.Error(), "out of bounds memory access")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
BIN
internal/integration_test/fuzzcases/testdata/701.wasm
vendored
Normal file
BIN
internal/integration_test/fuzzcases/testdata/701.wasm
vendored
Normal file
Binary file not shown.
19
internal/integration_test/fuzzcases/testdata/701.wat
vendored
Normal file
19
internal/integration_test/fuzzcases/testdata/701.wat
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
(module
|
||||
(func (export "i32.extend16_s")
|
||||
i32.const 0xffff
|
||||
;; if this extends to 64 bit, the bit pattern of the value has all bits set
|
||||
i32.extend16_s
|
||||
;; then plus one to it results in zero offset.
|
||||
v128.load16x4_u offset=1 align=1
|
||||
unreachable
|
||||
)
|
||||
(func (export "i32.extend8_s")
|
||||
i32.const 0xff
|
||||
;; if this extends to 64 bit, the bit pattern of the value has all bits set
|
||||
i32.extend8_s
|
||||
;; then plus one to it results in zero offset.
|
||||
v128.load16x4_u offset=1 align=1
|
||||
unreachable
|
||||
)
|
||||
(memory 1 1)
|
||||
)
|
||||
Reference in New Issue
Block a user