diff --git a/api/layout/paths.go b/api/layout/paths.go index 1573d39ba..9b0dd82f0 100644 --- a/api/layout/paths.go +++ b/api/layout/paths.go @@ -47,6 +47,10 @@ func EntriesPathForLogIndex(seq, logSize uint64) string { // // If from >= treeSize or N == 0, the returned iterator will yield no elements. func Range(from, N, treeSize uint64) iter.Seq[RangeInfo] { + // Mostly hypothetical, but ensure we never overflow uint64. + if math.MaxUint64-from < N { + N = math.MaxUint64 - from + } return func(yield func(RangeInfo) bool) { // Range is empty if we're entirely beyond the extent of the tree, or we've been asked for zero items. if from >= treeSize || N == 0 { diff --git a/client/stream.go b/client/stream.go index 71c84dbf8..7b039557f 100644 --- a/client/stream.go +++ b/client/stream.go @@ -91,7 +91,7 @@ func EntryBundles(ctx context.Context, numWorkers uint, getSize TreeSizeFunc, ge // For each bundle, pop a future into the bundles channel and kick off an async request // to resolve it. - for ri := range layout.Range(fromEntry, fromEntry+N, treeSize) { + for ri := range layout.Range(fromEntry, N, treeSize) { select { case <-exit: return