block: qcow: Test rejection when backing file end exceeds cluster

Cover the case where backing_file_offset lies inside the first
cluster but backing_file_offset + backing_file_size crosses the
cluster boundary, so the end of the name spills outside.

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 20:08:22 +02:00
committed by Rob Bradford
parent a4e8d79650
commit cdd7220384

View File

@@ -2737,6 +2737,16 @@ mod unit_tests {
));
}
#[test]
fn backing_file_end_past_cluster() {
let cluster_size = 1u64 << DEFAULT_CLUSTER_BITS;
let err = read_header_with_patched_backing(cluster_size - 4, 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)