Fix overflow in chunk and reconciliation ranges
This commit is contained in:
@@ -63,12 +63,13 @@ func (c *Chunker) PrepareChunk(ctx context.Context, req contracts.ChunkInput) (c
|
||||
}
|
||||
|
||||
step := c.options.MaxUnits - c.options.OverlapUnits
|
||||
ranges := make([]source.ChunkRange, 0, (len(req.Source.Units)+step-1)/step)
|
||||
count := len(req.Source.Units) / step
|
||||
if len(req.Source.Units)%step != 0 {
|
||||
count++
|
||||
}
|
||||
ranges := make([]source.ChunkRange, 0, count)
|
||||
for start := 0; start < len(req.Source.Units); start += step {
|
||||
end := start + c.options.MaxUnits
|
||||
if end > len(req.Source.Units) {
|
||||
end = len(req.Source.Units)
|
||||
}
|
||||
end := start + min(c.options.MaxUnits, len(req.Source.Units)-start)
|
||||
ranges = append(ranges, source.ChunkRange{
|
||||
StartUnitID: req.Source.Units[start].ID,
|
||||
EndUnitID: req.Source.Units[end-1].ID,
|
||||
|
||||
Reference in New Issue
Block a user