From ea0b2a34380e43a63e37ec170f7a72404a49b015 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Wed, 18 Mar 2026 11:31:09 -0700 Subject: [PATCH] fix write_needle_blob_and_index to error on too-small V3 blob Go returns an error when the needle blob is too small for timestamp patching. Rust was silently skipping the patch and writing the blob with a stale/zero timestamp, which could cause data integrity issues during incremental replication that relies on AppendAtNs ordering. --- seaweed-volume/src/storage/volume.rs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/seaweed-volume/src/storage/volume.rs b/seaweed-volume/src/storage/volume.rs index 573940ca5..932fa1f6e 100644 --- a/seaweed-volume/src/storage/volume.rs +++ b/seaweed-volume/src/storage/volume.rs @@ -2498,14 +2498,20 @@ impl Volume { let blob_to_write = if self.version() == VERSION_3 { let ts_offset = NEEDLE_HEADER_SIZE + size.0 as usize + NEEDLE_CHECKSUM_SIZE; - if ts_offset + TIMESTAMP_SIZE <= needle_blob.len() { - blob_buf = needle_blob.to_vec(); - blob_buf[ts_offset..ts_offset + TIMESTAMP_SIZE] - .copy_from_slice(&append_at_ns.to_be_bytes()); - &blob_buf[..] - } else { - needle_blob + if ts_offset + TIMESTAMP_SIZE > needle_blob.len() { + return Err(VolumeError::Io(io::Error::new( + io::ErrorKind::InvalidData, + format!( + "needle blob buffer too small: need {} bytes, have {}", + ts_offset + TIMESTAMP_SIZE, + needle_blob.len() + ), + ))); } + blob_buf = needle_blob.to_vec(); + blob_buf[ts_offset..ts_offset + TIMESTAMP_SIZE] + .copy_from_slice(&append_at_ns.to_be_bytes()); + &blob_buf[..] } else { needle_blob };