fix(io): guard sampled_offsets index in get_line() to prevent panic on corrupt cache
Replace direct indexing with .get()? to return None instead of panicking when sampled_offsets is shorter than expected (e.g. corrupt bincode cache). Closes #3
This commit is contained in:
@@ -233,7 +233,7 @@ impl LineIndex {
|
||||
}
|
||||
let block = idx / BLOCK_SIZE;
|
||||
let offset_in_block = idx % BLOCK_SIZE;
|
||||
let mut pos = self.sampled_offsets[block] as usize;
|
||||
let mut pos = (*self.sampled_offsets.get(block)?) as usize;
|
||||
for _ in 0..offset_in_block {
|
||||
match memchr::memchr(b'\n', &data[pos..]) {
|
||||
Some(rel) => pos = pos + rel + 1,
|
||||
|
||||
Reference in New Issue
Block a user