block: qcow: Reject backing file offset with zero size

A qcow2 header with non-zero backing_file_offset that points at a
zero length name is malformed. The parser would otherwise read an
empty path string and store it as a backing file. Reject it 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:
Anatol Belski
2026-06-01 17:35:10 +02:00
committed by Rob Bradford
parent 39e9376f5b
commit 53a9ae08c2
2 changed files with 7 additions and 0 deletions

View File

@@ -336,6 +336,11 @@ impl QcowHeader {
header.backing_file_size,
));
}
if header.backing_file_offset != 0 && header.backing_file_size == 0 {
return Err(Error::BackingFileOffsetWithoutSize(
header.backing_file_offset,
));
}
if header.backing_file_offset != 0 {
let cluster_size = 1u64
.checked_shl(header.cluster_bits)

View File

@@ -66,6 +66,8 @@ use crate::error::{BlockError, BlockErrorKind, BlockResult};
pub enum Error {
#[error("Backing file I/O error: {0}")]
BackingFileIo(String /* path */, #[source] io::Error),
#[error("Backing file offset {0:#x} with zero size")]
BackingFileOffsetWithoutSize(u64),
#[error("Backing file open error: {0}")]
BackingFileOpen(String /* path */, #[source] Box<Error>),
#[error(