fix(common): use checked u32 conversion for simple_disk_cache block range (#10184)

to_block_range cast block indices with a raw as u32, silently truncating
past 64 TiB and reading the wrong region. Mirror the sibling guard in
disk_cache/cached_slice.rs and fail loudly with u32::try_from(...).expect.
This commit is contained in:
Yash Singh
2026-09-03 12:39:01 +02:00
committed by timvisee
parent 679f64946c
commit 98321ab554
@@ -51,12 +51,14 @@ const REMOTE_OPEN_OPTIONS: OpenOptions = OpenOptions {
};
fn to_block_range(byte_range: Range<u64>) -> Range<u32> {
let start = (byte_range.start / BLOCK_SIZE as u64) as u32;
let start = u32::try_from(byte_range.start / BLOCK_SIZE as u64)
.expect("file too large for block cache (>70 TiB)");
if byte_range.start >= byte_range.end {
// empty byte range returns empty block range
return start..start;
}
let end = byte_range.end.div_ceil(BLOCK_SIZE as u64) as u32;
let end = u32::try_from(byte_range.end.div_ceil(BLOCK_SIZE as u64))
.expect("file too large for block cache (>70 TiB)");
start..end
}