diff --git a/pkg/smartcontract/nef/nef.go b/pkg/smartcontract/nef/nef.go index c4958e500..effb07ab6 100644 --- a/pkg/smartcontract/nef/nef.go +++ b/pkg/smartcontract/nef/nef.go @@ -203,6 +203,10 @@ func (n *File) DecodeBinary(r *io.BinReader) { return } n.Script = r.ReadVarBytes(MaxScriptLength) + if len(n.Script) == 0 { + r.Err = errors.New("empty script") + return + } if !hash.Hash160(n.Script).Equals(n.Header.ScriptHash) { r.Err = errors.New("script hashes mismatch") return diff --git a/pkg/smartcontract/nef/nef_test.go b/pkg/smartcontract/nef/nef_test.go index 01ecc2b00..229d786a2 100644 --- a/pkg/smartcontract/nef/nef_test.go +++ b/pkg/smartcontract/nef/nef_test.go @@ -37,6 +37,13 @@ func TestEncodeDecodeBinary(t *testing.T) { checkDecodeError(t, expected) }) + t.Run("zero-length script", func(t *testing.T) { + expected.Script = make([]byte, 0) + expected.Header.ScriptHash = hash.Hash160(expected.Script) + expected.Checksum = expected.Header.CalculateChecksum() + checkDecodeError(t, expected) + }) + t.Run("invalid script length", func(t *testing.T) { newScript := make([]byte, MaxScriptLength+1) expected.Script = newScript