mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Test rejection when backing file offset exceeds cluster
Cover an offset that lies well past the end of the first cluster to make sure the bound check fires for arbitrary out of range offsets rather than only the boundary case. Assisted-by: Claude:Opus-4.7 Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
2d8811ad82
commit
a4e8d79650
@@ -2727,6 +2727,16 @@ mod unit_tests {
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn backing_file_offset_past_cluster() {
|
||||
let cluster_size = 1u64 << DEFAULT_CLUSTER_BITS;
|
||||
let err = read_header_with_patched_backing(cluster_size + 4096, 16).unwrap_err();
|
||||
assert!(matches!(
|
||||
err,
|
||||
Error::BackingFileOutsideFirstCluster(_, _, _)
|
||||
));
|
||||
}
|
||||
|
||||
/// Helper to create a test file with header extensions
|
||||
fn create_header_with_extension(ext_type: u32, ext_data: &[u8]) -> (RawFile, QcowHeader) {
|
||||
let header = QcowHeader::create_for_size_and_path(3, 0x10_0000, None)
|
||||
|
||||
Reference in New Issue
Block a user