From bbf71d454c24adceb0a9f94d78b8d83e7c36439f Mon Sep 17 00:00:00 2001 From: Benjamen Keroack Date: Wed, 3 Jan 2018 09:36:39 -0800 Subject: [PATCH] disasm: fix incorrect stack depth for end/discard End/Discard ops were being misencoded with incorrect stack depths which caused stack underflows that manifested as slice index out of bounds runtime panics. --- disasm/disasm.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/disasm/disasm.go b/disasm/disasm.go index 66cda640..d2b9488b 100644 --- a/disasm/disasm.go +++ b/disasm/disasm.go @@ -184,7 +184,7 @@ func Disassemble(fn wasm.Function, module *wasm.Module) (*Disassembly, error) { // Same with ops.Br/BrIf, we subtract 2 instead of 1 // to get the depth of the *parent* block of the branch // we want to take. - prevDepthIndex := stackDepths.Len() - 2 + prevDepthIndex := stackDepths.Len() - 1 prevDepth := stackDepths.Get(prevDepthIndex) if op != ops.Else && blockSig != wasm.BlockTypeEmpty && !instr.Unreachable {