Skip to content

Commit 82a4cf9

Browse files
authored
Merge pull request #2592 from CortexFoundation/dev
finalize listIterator on parse error to prevent non-advancing loops
2 parents 87d0cba + ed1cbd8 commit 82a4cf9

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

rlp/iterator.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,24 @@ func NewListIterator(data RawValue) (*listIterator, error) {
3939

4040
}
4141

42-
// Next forwards the iterator one step, returns true if it was not at end yet
42+
// Next forwards the iterator one step.
43+
// Returns true if there is a next item or an error occurred on this step (check Err()).
44+
// On parse error, the iterator is marked finished and subsequent calls return false.
4345
func (it *listIterator) Next() bool {
4446
if len(it.data) == 0 {
4547
return false
4648
}
4749
_, t, c, err := readKind(it.data)
50+
if err != nil {
51+
it.next = nil
52+
it.err = err
53+
// Mark iteration as finished to avoid potential infinite loops on subsequent Next calls.
54+
it.data = nil
55+
return true
56+
}
4857
it.next = it.data[:t+c]
4958
it.data = it.data[t+c:]
50-
it.err = err
59+
it.err = nil
5160
return true
5261
}
5362

0 commit comments

Comments
 (0)