From d94be89a60cf466ad4ad60814ede869f6d695d72 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Mon, 16 Mar 2026 17:43:40 -0700 Subject: [PATCH] Add CompactMapSegment overflow panic guard matching Go --- seaweed-volume/src/storage/needle_map/compact_map.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/seaweed-volume/src/storage/needle_map/compact_map.rs b/seaweed-volume/src/storage/needle_map/compact_map.rs index debd5bf06..9dea94ce7 100644 --- a/seaweed-volume/src/storage/needle_map/compact_map.rs +++ b/seaweed-volume/src/storage/needle_map/compact_map.rs @@ -114,6 +114,14 @@ impl Segment { size, }; + // Match Go panic: don't exceed segment capacity + if self.list.len() >= SEGMENT_CHUNK_SIZE as usize { + panic!( + "attempted to write more than {} entries on CompactMapSegment", + SEGMENT_CHUNK_SIZE + ); + } + if self.list.len() == SEGMENT_CHUNK_SIZE as usize - 1 { // Pin capacity to exact size when maxing out let mut new_list = Vec::with_capacity(SEGMENT_CHUNK_SIZE as usize);