fix(host): check cluster is valid before do qemuimg convert (#24947)

This commit is contained in:
wanyaoqi
2026-06-02 20:02:04 +08:00
committed by GitHub
parent 69d3a2d894
commit 17e67af77c
+10
View File
@@ -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,