mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Reject backing file size with zero offset
A qcow2 header with backing_file_offset == 0 indicates the image has no backing file, so any non-zero backing_file_size is malformed. Qemu silently ignores the size in this case, which hides image corruption. Reject it explicitly with a dedicated error so the user gets a clear diagnostic. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
4294a4b862
commit
39e9376f5b
@@ -331,6 +331,11 @@ impl QcowHeader {
|
||||
if header.backing_file_size > MAX_BACKING_FILE_SIZE {
|
||||
return Err(Error::BackingFileTooLong(header.backing_file_size as usize));
|
||||
}
|
||||
if header.backing_file_offset == 0 && header.backing_file_size != 0 {
|
||||
return Err(Error::BackingFileSizeWithoutOffset(
|
||||
header.backing_file_size,
|
||||
));
|
||||
}
|
||||
if header.backing_file_offset != 0 {
|
||||
let cluster_size = 1u64
|
||||
.checked_shl(header.cluster_bits)
|
||||
|
||||
@@ -74,6 +74,8 @@ pub enum Error {
|
||||
BackingFileOutsideFirstCluster(u64, u32, u64),
|
||||
#[error("Backing file name at offset {0:#x} length {1:#x} overlaps header of size {2:#x}")]
|
||||
BackingFileOverlapsHeader(u64, u32, u32),
|
||||
#[error("Backing file size {0:#x} with zero offset")]
|
||||
BackingFileSizeWithoutOffset(u32),
|
||||
#[error("Backing file support is disabled")]
|
||||
BackingFilesDisabled,
|
||||
#[error("Backing file name is too long: {0} bytes over")]
|
||||
|
||||
Reference in New Issue
Block a user