forked from TrueCloudLab/neoneo-go
nef: forbid NEFs with zero-length scripts
This commit is contained in:
parent
b92ea2a48a
commit
c5e39dfabf
2 changed files with 11 additions and 0 deletions
|
@ -203,6 +203,10 @@ func (n *File) DecodeBinary(r *io.BinReader) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
n.Script = r.ReadVarBytes(MaxScriptLength)
|
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) {
|
if !hash.Hash160(n.Script).Equals(n.Header.ScriptHash) {
|
||||||
r.Err = errors.New("script hashes mismatch")
|
r.Err = errors.New("script hashes mismatch")
|
||||||
return
|
return
|
||||||
|
|
|
@ -37,6 +37,13 @@ func TestEncodeDecodeBinary(t *testing.T) {
|
||||||
checkDecodeError(t, expected)
|
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) {
|
t.Run("invalid script length", func(t *testing.T) {
|
||||||
newScript := make([]byte, MaxScriptLength+1)
|
newScript := make([]byte, MaxScriptLength+1)
|
||||||
expected.Script = newScript
|
expected.Script = newScript
|
||||||
|
|
Loading…
Add table
Reference in a new issue