Merge pull request #375 from nspcc-dev/pushbytes-short-read-fix-361

vm: fix not failing PUSHBYTES* on short read
This commit is contained in:
Roman Khimov 2019-09-09 15:02:56 +03:00 committed by GitHub
commit b5d3c37a01
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View file

@ -242,6 +242,9 @@ func (v *VM) execute(ctx *Context, op Instruction) {
if op >= PUSHBYTES1 && op <= PUSHBYTES75 {
b := ctx.readBytes(int(op))
if b == nil {
panic("failed to read instruction parameter")
}
v.estack.PushVal(b)
return
}

View file

@ -60,6 +60,22 @@ func TestPushBytes1to75(t *testing.T) {
}
}
func TestPushBytesNoParam(t *testing.T) {
prog := make([]byte, 1)
prog[0] = byte(PUSHBYTES1)
vm := load(prog)
vm.Run()
assert.Equal(t, true, vm.state.HasFlag(faultState))
}
func TestPushBytesShort(t *testing.T) {
prog := make([]byte, 10)
prog[0] = byte(PUSHBYTES10) // but only 9 left in the `prog`
vm := load(prog)
vm.Run()
assert.Equal(t, true, vm.state.HasFlag(faultState))
}
func TestPushm1to16(t *testing.T) {
var prog []byte
for i := int(PUSHM1); i <= int(PUSH16); i++ {