Skip to contentSkip to conversation

vmdk: byteswap VMDK4Header.desc_offset field

PATCH Applied Stefan Hajnoczi 4 participants 6 messages Jun 10, 2013 – Jun 13, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vmdk: byteswap VMDK4Header.desc_offset field

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

---
 block/vmdk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
block/vmdk.c +5 -2
index 608daaf..ee50a73 100644
@@ -507,8 +507,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) {
Signature · 1 line
1.8.1.4
Applied
#1 lore raw

Am 10.06.2013 um 11:07 hat Stefan Hajnoczi geschrieben:

Quoted 4 lines

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

Thanks, applied to the block layer.

block/vmdk.c static int vmdk_open_vmdk4(BlockDriverState *bs, · line 515

Quoted 12 lines
block/vmdk.c +5 -2
@@ -507,8 +507,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);
+        }
     }

Splitting up the if condition wouldn't have been necessary, strictly speaking. But I don't mind too much here.

Kevin

#2 lore raw
Quoted 8 lines · Kevin Wolf

Am 10.06.2013 um 11:07 hat Stefan Hajnoczi geschrieben:

Quoted 4 lines

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

Thanks, applied to the block layer.

Quoted 15 lines

block/vmdk.c static int vmdk_open_vmdk4(BlockDriverState *bs, · line 515

Quoted 12 lines
block/vmdk.c +5 -2
@@ -507,8 +507,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);
+        }
     }

Splitting up the if condition wouldn't have been necessary, strictly speaking. But I don't mind too much here.

True. The reason I did it is because accessing header.desc_offset directly is a bad habit. Someone modifying the code might conclude it's safe to access directly when it actually only works for the limited cases of zero and non-zero.

Stefan

#3 lore raw

Am 10.06.2013 um 16:32 hat Stefan Hajnoczi geschrieben:

Quoted 25 lines · Kevin Wolf
Quoted 8 lines

Am 10.06.2013 um 11:07 hat Stefan Hajnoczi geschrieben:

Quoted 4 lines

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

Thanks, applied to the block layer.

Quoted 15 lines

block/vmdk.c static int vmdk_open_vmdk4(BlockDriverState *bs, · line 515

Quoted 12 lines
block/vmdk.c +5 -2
@@ -507,8 +507,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);
+        }
     }

Splitting up the if condition wouldn't have been necessary, strictly speaking. But I don't mind too much here.

Quoted 4 lines

True. The reason I did it is because accessing header.desc_offset directly is a bad habit. Someone modifying the code might conclude it's safe to access directly when it actually only works for the limited cases of zero and non-zero.

It just looks a bit weird because you're still doing the same for header.capacity and there's no real reason for treating the two fields differently.

Kevin

#4 lore raw
In reply to Stefan Hajnoczi
Quoted 25 lines · Stefan Hajnoczi
Quoted 8 lines · Kevin Wolf

Am 10.06.2013 um 11:07 hat Stefan Hajnoczi geschrieben:

Quoted 4 lines

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

Thanks, applied to the block layer.

Quoted 15 lines

block/vmdk.c static int vmdk_open_vmdk4(BlockDriverState *bs, · line 515

Quoted 12 lines
block/vmdk.c +5 -2
@@ -507,8 +507,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);
+        }
     }

Splitting up the if condition wouldn't have been necessary, strictly speaking. But I don't mind too much here.

Quoted 5 lines

True. The reason I did it is because accessing header.desc_offset directly is a bad habit. Someone modifying the code might conclude it's safe to access directly when it actually only works for the limited cases of zero and non-zero.

Not byteswapping header.capacity here, any reason?

Signature · 1 line
Fam
#5 lore raw
Quoted 26 lines · Fam Zheng
Quoted 25 lines · Stefan Hajnoczi
Quoted 23 lines · Kevin Wolf

Am 10.06.2013 um 11:07 hat Stefan Hajnoczi geschrieben:

Quoted 4 lines

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

Thanks, applied to the block layer.

block/vmdk.c static int vmdk_open_vmdk4(BlockDriverState *bs, · line 515

Quoted 12 lines
block/vmdk.c +5 -2
@@ -507,8 +507,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);
+        }
     }

Splitting up the if condition wouldn't have been necessary, strictly speaking. But I don't mind too much here.

Quoted 7 lines
Quoted 5 lines

True. The reason I did it is because accessing header.desc_offset directly is a bad habit. Someone modifying the code might conclude it's safe to access directly when it actually only works for the limited cases of zero and non-zero.

Not byteswapping header.capacity here, any reason?

Byteswapping header.capacity too is fine by me. This patch is focussed on just header.desc_offset.

Stefan