          header = footer.header;
      }
  
-@@ -645,11 +667,15 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
+@@ -645,11 +667,15 @@
          error_set(errp, QERR_UNKNOWN_BLOCK_FORMAT_FEATURE,
                    bs->device_name, "vmdk", buf);
          return -ENOTSUP;
 -    } else if (le32_to_cpu(header.version) == 3 && (flags & BDRV_O_RDWR)) {
 +    } else if (le32_to_cpu(header.version) == 3 &&
 +               (flags & BDRV_O_RDWR) &&
-+               !(le64_to_cpu(header.flags) & VMDK4_FLAG_COMPRESS)) {
++               !(le32_to_cpu(header.flags) & VMDK4_FLAG_COMPRESS)) {
          /* VMware KB 2064959 explains that version 3 added support for
           * persistent changed block tracking (CBT), and backup software can
           * read it as version=1 if it doesn't care about the changed area

     }
     if (extent->has_zero_grain && *cluster_offset == VMDK_GTE_ZEROED) {
         zeroed = true;
@@ -1119,7 +1264,7 @@ static int get_cluster_offset(BlockDriverState *bs,
         }
 
         *cluster_offset >>= 9;

 
     ret = bdrv_create_file(filename, opts, &local_err);
     if (ret < 0) {
@@ -1562,28 +1718,38 @@
     }
     magic = cpu_to_be32(VMDK4_MAGIC);
     memset(&header, 0, sizeof(header));
