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