Range reads M0/M1 (indexed lookups, Storage trait), ZFP, in-place editing #17

Merged
osobh merged 52 commits from feat/p3-range-zfp-edit into main 2026-09-26 20:42:22 +00:00
3 changed files with 27 additions and 10 deletions
Showing only changes of commit aab7ea9e8f - Show all commits
+10 -6
View File
@@ -385,13 +385,13 @@ impl ObjectHeader {
}
let chunk0_msg_start = pos;
let chunk0_msg_end = abs(pos)
.checked_add(chunk0_size)
.ok_or(FormatError::UnexpectedEof {
let Some(chunk0_abs_end) = abs(pos).checked_add(chunk0_size) else {
return Err(FormatError::UnexpectedEof {
expected: usize::MAX,
available: file_len,
})?
- base;
});
};
let chunk0_msg_end = chunk0_abs_end - base;
// The whole first chunk, prefix to checksum, in one read (its
// bounds check is the one on the checksum's 4 bytes).
@@ -1364,7 +1364,11 @@ mod tests {
let want = ObjectHeader::parse(&f, at, 8, 8);
let storage = CountingStorage::new(f.clone());
let got = ObjectHeader::parse_in(&storage, at as u64, 8, 8);
assert_eq!(format!("{got:?}"), format!("{want:?}"), "at {at}, cut {cut}");
assert_eq!(
format!("{got:?}"),
format!("{want:?}"),
"at {at}, cut {cut}"
);
}
}
}
+5 -1
View File
@@ -215,7 +215,11 @@ pub fn read_exact_at(
/// storage. For structures whose size is only known once their prefix has
/// been parsed and whose parsers bound-check what they are given.
#[inline]
pub fn read_upto(file: &dyn Storage, offset: u64, max: usize) -> Result<Cow<'_, [u8]>, FormatError> {
pub fn read_upto(
file: &dyn Storage,
offset: u64,
max: usize,
) -> Result<Cow<'_, [u8]>, FormatError> {
let avail = file.len().saturating_sub(offset);
let len = usize::try_from(avail).map_or(max, |a| a.min(max));
let bytes = file.read_at(offset, len)?;
+12 -3
View File
@@ -520,7 +520,10 @@ fn image_block_in(
}
/// Where the image block is, checked against a file of `file_len` bytes.
fn image_block_range(file_len: u64, location: CacheImageLocation) -> Result<(u64, usize), FormatError> {
fn image_block_range(
file_len: u64,
location: CacheImageLocation,
) -> Result<(u64, usize), FormatError> {
let bad = FormatError::InvalidCacheImage;
let start = usize::try_from(location.address).map_err(|_| bad("address out of range"))?;
let len = usize::try_from(location.length).map_err(|_| bad("length out of range"))?;
@@ -883,9 +886,15 @@ mod tests {
read_superblock_extension_in(&storage, &sb),
read_superblock_extension(&f, &sb)
);
assert_eq!(cache_image_state_in(&storage, &sb), cache_image_state(&f, &sb));
assert_eq!(
cache_image_state_in(&storage, &sb),
cache_image_state(&f, &sb)
);
if let Ok(CacheImageState::Loaded(image)) = cache_image_state(&f, &sb) {
assert_eq!(&*image.block_in(&storage).unwrap(), image.block(&f).unwrap());
assert_eq!(
&*image.block_in(&storage).unwrap(),
image.block(&f).unwrap()
);
}
}
}