@@ -428,11 +428,14 @@ func Disassemble(code []byte) ([]Instr, error) {
428428 }
429429 instr .Immediates = append (instr .Immediates , index )
430430 if op == ops .CallIndirect {
431- reserved , err := leb128 . ReadVarUint32 (reader )
431+ idx , err := wasm . ReadByte (reader )
432432 if err != nil {
433433 return nil , err
434434 }
435- instr .Immediates = append (instr .Immediates , reserved )
435+ if idx != 0x00 {
436+ return nil , errors .New ("disasm: table index in call_indirect must be 0" )
437+ }
438+ instr .Immediates = append (instr .Immediates , uint32 (idx ))
436439 }
437440 case ops .GetLocal , ops .SetLocal , ops .TeeLocal , ops .GetGlobal , ops .SetGlobal :
438441 index , err := leb128 .ReadVarUint32 (reader )
@@ -468,23 +471,26 @@ func Disassemble(code []byte) ([]Instr, error) {
468471 instr .Immediates = append (instr .Immediates , math .Float64frombits (i ))
469472 case ops .I32Load , ops .I64Load , ops .F32Load , ops .F64Load , ops .I32Load8s , ops .I32Load8u , ops .I32Load16s , ops .I32Load16u , ops .I64Load8s , ops .I64Load8u , ops .I64Load16s , ops .I64Load16u , ops .I64Load32s , ops .I64Load32u , ops .I32Store , ops .I64Store , ops .F32Store , ops .F64Store , ops .I32Store8 , ops .I32Store16 , ops .I64Store8 , ops .I64Store16 , ops .I64Store32 :
470473 // read memory_immediate
471- flags , err := leb128 .ReadVarUint32 (reader )
474+ align , err := leb128 .ReadVarUint32 (reader )
472475 if err != nil {
473476 return nil , err
474477 }
475- instr .Immediates = append (instr .Immediates , flags )
478+ instr .Immediates = append (instr .Immediates , align )
476479
477480 offset , err := leb128 .ReadVarUint32 (reader )
478481 if err != nil {
479482 return nil , err
480483 }
481484 instr .Immediates = append (instr .Immediates , offset )
482485 case ops .CurrentMemory , ops .GrowMemory :
483- res , err := leb128 . ReadVarUint32 (reader )
486+ idx , err := wasm . ReadByte (reader )
484487 if err != nil {
485488 return nil , err
486489 }
487- instr .Immediates = append (instr .Immediates , uint8 (res ))
490+ if idx != 0x00 {
491+ return nil , errors .New ("disasm: memory index must be 0" )
492+ }
493+ instr .Immediates = append (instr .Immediates , uint8 (idx ))
488494 }
489495 out = append (out , instr )
490496 }
0 commit comments