Skip to content

Commit cfb3320

Browse files
Replace todo!() with proper error handling in deletion vector (#1447)
- Replace todo!() macro with Error::DeletionVector for unsupported native serialization - Prevents potential panic in production code when encountering inline bitmaps with native serialization (magic number 1681511376) - Error message: 'Native serialization in inline bitmaps is not yet supported' Solves the issue #1441 ## How was this change tested? new UT --------- Co-authored-by: Zach Schuermann <[email protected]>
1 parent 1a58987 commit cfb3320

File tree

1 file changed

+33
-3
lines changed

1 file changed

+33
-3
lines changed

kernel/src/actions/deletion_vector.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,9 @@ impl DeletionVectorDescriptor {
220220
match magic {
221221
1681511377 => RoaringTreemap::deserialize_from(&byte_slice[4..])
222222
.map_err(|err| Error::DeletionVector(err.to_string())),
223-
1681511376 => {
224-
todo!("Don't support native serialization in inline bitmaps yet");
225-
}
223+
1681511376 => Err(Error::deletion_vector(
224+
"Native serialization in inline bitmaps is not yet supported",
225+
)),
226226
_ => Err(Error::DeletionVector(format!("Invalid magic {magic}"))),
227227
}
228228
}
@@ -555,6 +555,36 @@ mod tests {
555555
}
556556
}
557557

558+
#[test]
559+
fn test_inline_native_serialization_error() {
560+
// Construct an inline DV payload whose first 4 bytes (little-endian) are the
561+
// native serialization magic (1681511376). The `read` method should return
562+
// a DeletionVector error indicating native serialization isn't supported.
563+
let sync_engine = SyncEngine::new();
564+
let storage = sync_engine.storage_handler();
565+
let parent = Url::parse("http://not.used").unwrap();
566+
567+
let mut bytes = Vec::new();
568+
// native serialization magic (little-endian)
569+
bytes.extend_from_slice(&1681511376u32.to_le_bytes());
570+
// some trailing bytes (content not important for this test)
571+
bytes.extend_from_slice(&[1u8, 2, 3, 4]);
572+
573+
let encoded = z85::encode(&bytes);
574+
575+
let inline = DeletionVectorDescriptor {
576+
storage_type: DeletionVectorStorageType::Inline,
577+
path_or_inline_dv: encoded,
578+
offset: None,
579+
size_in_bytes: bytes.len() as i32,
580+
cardinality: 0,
581+
};
582+
583+
let err = inline.read(storage, &parent).unwrap_err();
584+
let msg = err.to_string();
585+
assert!(msg.contains("Native serialization in inline bitmaps is not yet supported"));
586+
}
587+
558588
#[test]
559589
fn test_deletion_vector_read() {
560590
let path =

0 commit comments

Comments
 (0)