Avoid duplicating blocks and txs on privkey imports.
When detaching the tail end of a slice of blocks or transactions and appending the newly inserted middle block, and the previous tail, the capacity of the slice head must be limited to prevent overwriting the newly inserted block/tx in the same memory as the tail slice. Bug discovered by @mably while working on the peercoin port of btcwallet and reported on IRC.
This commit is contained in:
parent
b55a9ed7ca
commit
596a3154c1
1 changed files with 2 additions and 2 deletions
|
@ -358,7 +358,7 @@ func (s *Store) blockCollectionForInserts(block *Block) *blockTxCollection {
|
|||
i--
|
||||
}
|
||||
detached := s.blocks[i:]
|
||||
s.blocks = append(s.blocks[:i], b)
|
||||
s.blocks = append(s.blocks[:i:i], b)
|
||||
s.blockIndexes[b.Height] = i
|
||||
for i, b := range detached {
|
||||
newIndex := uint32(i + len(s.blocks))
|
||||
|
@ -399,7 +399,7 @@ func (c *blockTxCollection) txRecordForInserts(tx *btcutil.Tx) *txRecord {
|
|||
i--
|
||||
}
|
||||
detached := c.txs[i:]
|
||||
c.txs = append(c.txs[:i], record)
|
||||
c.txs = append(c.txs[:i:i], record)
|
||||
c.txIndexes[tx.Index()] = i
|
||||
for i, r := range detached {
|
||||
newIndex := uint32(i + len(c.txs))
|
||||
|
|
Loading…
Reference in a new issue