Subject: [PATCH 03/13] vmdk: byteswap VMDK4Header.desc_offset field

From: Fam Zheng <[email-masked]>
Date: Thu, 8 Aug 2013 06:09:33 +0200

RH-Author: Fam Zheng <[email-masked]>
Message-id: <[email-masked]>
Patchwork-id: 53068
O-Subject: [RHEL-6.5 qemu-kvm PATCH 03/11] vmdk: byteswap VMDK4Header.desc_offset field
Bugzilla: 994804
RH-Acked-by: Kevin Wolf <[email-masked]>
RH-Acked-by: Stefan Hajnoczi <[email-masked]>
RH-Acked-by: Jeffrey Cody <[email-masked]>

From: Stefan Hajnoczi <[email-masked]>

Remember to byteswap VMDK4Header.desc_offset on big-endian machines.

Cc: [email-masked]
Signed-off-by: Stefan Hajnoczi <[email-masked]>
Signed-off-by: Kevin Wolf <[email-masked]>
(cherry picked from commit 5a394b9e96eb3c39676353bdf8a230180ae8d6f4)
Signed-off-by: Fam Zheng <[email-masked]>
---
 block/vmdk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

Signed-off-by: Michal Novotny <[email-masked]>
---
 block/vmdk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index deb6743..8d17b9b 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -505,8 +505,11 @@ static int vmdk_open_vmdk4(BlockDriverState *bs,
     if (ret < 0) {
         return ret;
     }
-    if (header.capacity == 0 && header.desc_offset) {
-        return vmdk_open_desc_file(bs, flags, header.desc_offset << 9);
+    if (header.capacity == 0) {
+        int64_t desc_offset = le64_to_cpu(header.desc_offset);
+        if (desc_offset) {
+            return vmdk_open_desc_file(bs, flags, desc_offset << 9);
+        }
     }
 
     if (le64_to_cpu(header.gd_offset) == VMDK4_GD_AT_END) {
-- 
1.7.11.7