mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-22 03:30:35 +00:00
Fix out of bound check in AncestorRoot
(#7226)
* Move out of bound check to the correct scope * Merge refs/heads/master into store-out-of-bound
This commit is contained in:
parent
fcfd828725
commit
e1aa920fc6
@ -414,3 +414,24 @@ func TestStore_AncestorRoot(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, bytesutil.ToBytes32(r), [32]byte{'b'})
|
||||
}
|
||||
|
||||
func TestStore_AncestorRootOutOfBound(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
f := &ForkChoice{store: &Store{}}
|
||||
f.store.nodesIndices = map[[32]byte]uint64{}
|
||||
_, err := f.AncestorRoot(ctx, [32]byte{'a'}, 0)
|
||||
assert.ErrorContains(t, "node does not exist", err)
|
||||
f.store.nodesIndices[[32]byte{'a'}] = 0
|
||||
_, err = f.AncestorRoot(ctx, [32]byte{'a'}, 0)
|
||||
assert.ErrorContains(t, "node index out of range", err)
|
||||
f.store.nodesIndices[[32]byte{'b'}] = 1
|
||||
f.store.nodesIndices[[32]byte{'c'}] = 2
|
||||
f.store.nodes = []*Node{
|
||||
{slot: 1, root: [32]byte{'a'}, parent: NonExistentNode},
|
||||
{slot: 2, root: [32]byte{'b'}, parent: 100}, // Out of bound parent.
|
||||
{slot: 3, root: [32]byte{'c'}, parent: 1},
|
||||
}
|
||||
|
||||
_, err = f.AncestorRoot(ctx, [32]byte{'c'}, 1)
|
||||
require.ErrorContains(t, "node index out of range", err)
|
||||
}
|
||||
|
@ -169,9 +169,10 @@ func (f *ForkChoice) AncestorRoot(ctx context.Context, root [32]byte, slot uint6
|
||||
}
|
||||
|
||||
i = f.store.nodes[i].parent
|
||||
}
|
||||
if i >= uint64(len(f.store.nodes)) {
|
||||
return nil, errors.New("node index out of range")
|
||||
|
||||
if i >= uint64(len(f.store.nodes)) {
|
||||
return nil, errors.New("node index out of range")
|
||||
}
|
||||
}
|
||||
|
||||
return f.store.nodes[i].root[:], nil
|
||||
|
Loading…
Reference in New Issue
Block a user