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 <rbradford@meta.com>
This commit is contained in:
Rob Bradford
2026-07-08 07:45:00 -07:00
parent 8d3859af0d
commit 5b99f9ce41

View File

@@ -576,8 +576,12 @@ impl QcowHeader {
buf.extend_from_slice(v3.as_bytes()); buf.extend_from_slice(v3.as_bytes());
if self.header_size > V3_BARE_HEADER_SIZE { if self.header_size > V3_BARE_HEADER_SIZE {
// no compression let compression_type = match &self.compression_type {
buf.extend_from_slice(BeU64::new(0).as_bytes()); 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(); let end_extension = ExtensionHeader::end();