parser: use nil to indicate zero-count vectors
This commit is contained in:
parent
dfb05c261d
commit
2d9cf24f74
|
@ -276,6 +276,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
|||
// TODO: vector. At the moment we're assuming trusted input.
|
||||
// See https://nvd.nist.gov/vuln/detail/CVE-2018-17144 for an example.
|
||||
|
||||
if txInCount > 0 {
|
||||
tx.transparentInputs = make([]*txIn, txInCount)
|
||||
for i := 0; i < txInCount; i++ {
|
||||
ti := &txIn{}
|
||||
|
@ -285,12 +286,14 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
|||
}
|
||||
tx.transparentInputs[i] = ti
|
||||
}
|
||||
}
|
||||
|
||||
var txOutCount uint64
|
||||
if ok := s.ReadCompactSize(&txOutCount); !ok {
|
||||
return nil, errors.New("could not read tx_out_count")
|
||||
}
|
||||
|
||||
if txOutCount > 0 {
|
||||
tx.transparentOutputs = make([]*txOut, txOutCount)
|
||||
for i := 0; i < txOutCount; i++ {
|
||||
to := &txOut{}
|
||||
|
@ -300,6 +303,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
|||
}
|
||||
tx.transparentOutputs[i] = to
|
||||
}
|
||||
}
|
||||
|
||||
if ok := s.ReadUint32(&tx.nLockTime); !ok {
|
||||
return nil, errors.New("could not read nLockTime")
|
||||
|
@ -321,6 +325,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
|||
return nil, errors.New("could not read nShieldedSpend")
|
||||
}
|
||||
|
||||
if spendCount > 0 {
|
||||
tx.shieldedSpends = make([]*spend, spendCount)
|
||||
for i := 0; i < spendCount; i++ {
|
||||
newSpend := &spend{}
|
||||
|
@ -330,12 +335,14 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
|||
}
|
||||
tx.shieldedSpends[i] = newSpend
|
||||
}
|
||||
}
|
||||
|
||||
var outputCount uint64
|
||||
if ok := s.ReadCompactSize(&outputCount); !ok {
|
||||
return nil, errors.New("could not read nShieldedOutput")
|
||||
}
|
||||
|
||||
if outputCount > 0 {
|
||||
tx.shieldedOutputs = make([]*output, outputCount)
|
||||
for i := 0; i < outputCount; i++ {
|
||||
newOutput := &output{}
|
||||
|
@ -346,6 +353,7 @@ func (tx *transaction) ParseFromSlice(data []byte) ([]byte, error) {
|
|||
tx.shieldedOutputs[i] = newOutput
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if tx.version >= 2 {
|
||||
var joinSplitCount uint64
|
||||
|
|
Loading…
Reference in New Issue