From bef0b44e916b064083eaba18ca203829f371f49a Mon Sep 17 00:00:00 2001 From: dailz Date: Wed, 3 Jun 2026 15:39:05 +0800 Subject: [PATCH] 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 --- crates/core/src/io/line_index.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/core/src/io/line_index.rs b/crates/core/src/io/line_index.rs index 0ba2fcd..eac43b4 100644 --- a/crates/core/src/io/line_index.rs +++ b/crates/core/src/io/line_index.rs @@ -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,