Skip to content

Commit 2889a42

Browse files
author
Achille Roussel
committed
add safeguards
1 parent 3a75402 commit 2889a42

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

protocol/buffer.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,14 @@ func (pages contiguousPages) indexOf(offset int64) int {
463463
if len(pages) == 0 {
464464
return 0
465465
}
466-
return int((offset - pages[0].offset) / pageSize)
466+
i := int((offset - pages[0].offset) / pageSize)
467+
if i < 0 {
468+
i = 0
469+
}
470+
if i > len(pages) {
471+
i = len(pages)
472+
}
473+
return i
467474
}
468475

469476
func (pages contiguousPages) scan(begin, end int64, f func([]byte) bool) {

0 commit comments

Comments
 (0)