From 5b99f9ce413cf85ae0d69079e9f0a263c6abc8bd Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 8 Jul 2026 07:45:00 -0700 Subject: [PATCH] block: qcow: Preserve the compression type when writing the header When writing the header after a resize the compression type field was always set to 0, which selects zlib, even when the image was originally created with zstd. The resized image would then no longer be usable. Write the actual configured compression type instead. Fixes: #8558 Assisted-by: Claude:Opus-4.8 Signed-off-by: Rob Bradford --- block/src/formats/qcow/header.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/block/src/formats/qcow/header.rs b/block/src/formats/qcow/header.rs index c9a8c33c5..5f56bb419 100644 --- a/block/src/formats/qcow/header.rs +++ b/block/src/formats/qcow/header.rs @@ -576,8 +576,12 @@ impl QcowHeader { buf.extend_from_slice(v3.as_bytes()); if self.header_size > V3_BARE_HEADER_SIZE { - // no compression - buf.extend_from_slice(BeU64::new(0).as_bytes()); + let compression_type = match &self.compression_type { + CompressionType::Zlib => COMPRESSION_TYPE_ZLIB, + CompressionType::Zstd => COMPRESSION_TYPE_ZSTD, + }; + let compression_type = BeU64::new(compression_type << (64 - 8)); + buf.extend_from_slice(compression_type.as_bytes()); } let end_extension = ExtensionHeader::end();