From 17e67af77c2e147aa4fe7fda1883fa12666d29eb Mon Sep 17 00:00:00 2001 From: wanyaoqi <18528551+wanyaoqi@users.noreply.github.com> Date: Tue, 2 Jun 2026 20:02:04 +0800 Subject: [PATCH] fix(host): check cluster is valid before do qemuimg convert (#24947) --- pkg/util/qemuimg/qemuimg.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pkg/util/qemuimg/qemuimg.go b/pkg/util/qemuimg/qemuimg.go index 379508fa15..46c8f34c5b 100644 --- a/pkg/util/qemuimg/qemuimg.go +++ b/pkg/util/qemuimg/qemuimg.go @@ -507,6 +507,13 @@ func convertEncrypt(srcInfo, destInfo SImageInfo, compact bool, workerOpions []s return nil } +func isValidClusterSize(size int) bool { + if size < 512 || size > 2*1024*1024 { + return false + } + return true +} + func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageFormat, compact bool, password string, encryptFormat TEncryptFormat, encryptAlg seclib2.TSymEncAlg) error { if !img.IsValid() { return fmt.Errorf("self is not valid") @@ -515,6 +522,9 @@ func (img *SQemuImage) doConvert(targetPath string, format qemuimgfmt.TImageForm if compact { destClusterSize = DefaultQcow2ClusterSize } + if format == qemuimgfmt.QCOW2 && !isValidClusterSize(destClusterSize) { + destClusterSize = DefaultQcow2ClusterSize + } return Convert(SImageInfo{ Path: img.Path, Format: img.Format,