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:
Anatol Belski
2026-05-29 19:31:16 +02:00
committed by Rob Bradford
parent 2d8811ad82
commit a4e8d79650

View File

@@ -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)