Fix overflow in chunk and reconciliation ranges

This commit is contained in:
2026-11-26 01:26:46 +00:00
parent cecd68f161
commit 4026e26e76
6 changed files with 77 additions and 10 deletions

View File

@@ -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,