go-interpreter / wagon

wagon, a WebAssembly-based Go interpreter, for Go.
BSD 3-Clause "New" or "Revised" License
904 stars 148 forks source link

end/else will discard the elements to restore stack height. however spec only define br relate opcode do that operaton #157

Closed carltraveler closed 5 years ago

carltraveler commented 5 years ago

like bolow code: (module (type (;0;) (func (result i32))) (func (;0;) (type 0) (result i32) (local i32 i32) block i32.const 1 if i32.const 10 i32.const 2 i32.const 2 i32.const 0 br_if 1 end end i32.const 9 ) (export "loop" (func 0))) the 'end' opcode can restore height. this is not coherence with spec. and this code can not pass by wasm-validate. however can run ok with wagon

carltraveler commented 5 years ago

same issue with else opcode. I think if end or else code need discard element. will cause panic.

twitchyliquid64 commented 5 years ago

I was under the impression that blocks must finish with the same stack height as their parent to be valid (after accounting for any return type), is this correct?

If so, it should be sufficient to improve wagon's validation to detect this?

Can you test is #161 addresses this bug?

twitchyliquid64 commented 5 years ago

161 is merged, so can you retest with the latest (v0.6.0) ?

twitchyliquid64 commented 5 years ago

Closing as I think this is addressed in v0.6.0, and the issue with else/if on refs/master/head.