mirror of
https://github.com/qdrant/qdrant.git
synced 2026-09-21 13:37:46 -05:00
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:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user