Skip to content

Commit 9093cb0

Browse files
fix(bm25): clamp startPos in skipTo to prevent negative sort.Search length
Defensive hardening from GPT-5 review: if inBlockPos exceeds block length after next() reaches end of block, the sort.Search span could go negative. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 3503a9c commit 9093cb0

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

worker/bm25wand.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ func (it *listIter) skipTo(target uint64) bool {
188188
startPos := it.inBlockPos
189189
if startPos < 0 {
190190
startPos = 0
191+
} else if startPos > len(it.block) {
192+
startPos = len(it.block)
191193
}
192194
// Binary search within current block from startPos.
193195
pos := sort.Search(len(it.block)-startPos, func(i int) bool {

0 commit comments

Comments
 (0)