nef: forbid NEFs with zero-length scripts

This commit is contained in:
Roman Khimov 2020-11-18 12:57:44 +03:00
parent b92ea2a48a
commit c5e39dfabf
2 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -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