transaction: don't overwrite error and witnesses length check

ReadArray() can return some error and we shouldn't overwrite it. At the same
time limiting ReadArray() to the number of Signers can make it return wrong
error if the number of witnesses actually is bigger than the number of
signers, so use MaxAttributes.
This commit is contained in:
Roman Khimov 2021-08-04 23:17:50 +03:00
parent d487b54612
commit d2732a71d8

View file

@ -148,8 +148,8 @@ func (t *Transaction) decodeBinaryNoSize(br *io.BinReader) {
if br.Err != nil {
return
}
br.ReadArray(&t.Scripts, len(t.Signers))
if len(t.Signers) != len(t.Scripts) {
br.ReadArray(&t.Scripts, MaxAttributes)
if br.Err == nil && len(t.Signers) != len(t.Scripts) {
br.Err = fmt.Errorf("%w: %d vs %d", ErrInvalidWitnessNum, len(t.Signers), len(t.Scripts))
return
}