Skip to contentSkip to conversation

vmdk: Fix integer overflow in offset calculation

PATCH Superseded Fam Zheng 4 participants 5 messages Sep 22, 2014 – Sep 23, 2014 Block layer

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Fam Zheng

author
#0 lore raw

PATCH v4 1/1 vmdk: Fix integer overflow in offset calculation

This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).

$ ~/build/master/qemu-io /stor/vm/arch.vmdk -c 'write 2G 1k'
write failed: Invalid argument

---
v4: Fix typo in file header: 1014 -> 2014.
v3: A new case 105 instead of embedding in 005. (Max)

---
 block/vmdk.c               |  2 +-
 tests/qemu-iotests/105     | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/105.out | 21 ++++++++++++++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100755 tests/qemu-iotests/105
 create mode 100644 tests/qemu-iotests/105.out
block/vmdk.c +1 -1
index afdea1a..4ae6c75 100644
@@ -1113,7 +1113,7 @@ static int get_cluster_offset(BlockDriverState *bs,
     uint32_t min_count, *l2_table;
     bool zeroed = false;
     int64_t ret;
-    int32_t cluster_sector;
+    int64_t cluster_sector;
 
     if (m_data) {
         m_data->valid = 0;
tests/qemu-iotests/105 new file +70 -0

70 lines not on this page · raw message

tests/qemu-iotests/105.out new file +21 -0
new file mode 100644
index 0000000..de47061
@@ -0,0 +1,21 @@
+QA output created by 105
+
+creating large image
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=17592186044416
+
+small read
+read 4096/4096 bytes at offset 1024
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+small write
+wrote 4096/4096 bytes at offset 8192
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+small read at high offset
+read 4096/4096 bytes at offset 4398046511104
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+
+small write at high offset
+wrote 4096/4096 bytes at offset 4398046511104
+4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
+*** done
Signature · 1 line
1.9.3
Reviewed-by on v4 1/1
#1 lore raw
Quoted 12 lines · Fam Zheng

This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).

$ ~/build/master/qemu-io /stor/vm/arch.vmdk -c 'write 2G 1k'
write failed: Invalid argument

---
v4: Fix typo in file header: 1014 -> 2014.
v3: A new case 105 instead of embedding in 005. (Max)

Quoted 7 lines
---
 block/vmdk.c               |  2 +-
 tests/qemu-iotests/105     | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/105.out | 21 ++++++++++++++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100755 tests/qemu-iotests/105
 create mode 100644 tests/qemu-iotests/105.out
Reviewed-by on v4 1/1
#2 lore raw
In reply to Fam Zheng
Quoted 12 lines · Fam Zheng

This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).

$ ~/build/master/qemu-io /stor/vm/arch.vmdk -c 'write 2G 1k'
write failed: Invalid argument

---
v4: Fix typo in file header: 1014 -> 2014.
v3: A new case 105 instead of embedding in 005. (Max)

Quoted 7 lines
---
  block/vmdk.c               |  2 +-
  tests/qemu-iotests/105     | 70 ++++++++++++++++++++++++++++++++++++++++++++++
  tests/qemu-iotests/105.out | 21 ++++++++++++++
  3 files changed, 92 insertions(+), 1 deletion(-)

create mode 100755 tests/qemu-iotests/105
create mode 100644 tests/qemu-iotests/105.out

I'm sorry, but you didn't add the respective line to the group file. Also, the reference output is wrong; for the latter two accesses, it should be "at offset 15393162788864" (14T) instead of "at offset 4398046511104" (4T).

Those changes are trivial, though, so with an appropriate line in tests/qemu-iotests/group and %s/4398046511104/15393162788864/ in tests/qemu-iotests/105.out:

author
#3 lore raw
Quoted 21 lines · Max Reitz
Quoted 12 lines · Fam Zheng

This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).

$ ~/build/master/qemu-io /stor/vm/arch.vmdk -c 'write 2G 1k'
write failed: Invalid argument

---
v4: Fix typo in file header: 1014 -> 2014.
v3: A new case 105 instead of embedding in 005. (Max)

Quoted 7 lines
---
 block/vmdk.c               |  2 +-
 tests/qemu-iotests/105     | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/105.out | 21 ++++++++++++++
 3 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100755 tests/qemu-iotests/105
 create mode 100644 tests/qemu-iotests/105.out
Quoted 3 lines

I'm sorry, but you didn't add the respective line to the group file. Also, the reference output is wrong; for the latter two accesses, it should be "at offset 15393162788864" (14T) instead of "at offset 4398046511104" (4T).

Oops I saw a no-op when running check, but thought it passed!

Quoted 4 lines

Those changes are trivial, though, so with an appropriate line in tests/qemu-iotests/group and %s/4398046511104/15393162788864/ in tests/qemu-iotests/105.out:

Thanks so much for your careful reviewing! I am fixing this and picking up your rev-by line in v5.

Fam

Quoted 2 lines
#4 lore raw
In reply to Fam Zheng
Quoted 8 lines · Fam Zheng

This fixes the bug introduced by commit c6ac36e (vmdk: Optimize cluster allocation).

$ ~/build/master/qemu-io /stor/vm/arch.vmdk -c 'write 2G 1k'
write failed: Invalid argument

Unfortunately I don't have access to the VMWare system anymore (it belongs to a client) but I can at least confirm that applying your v4 patch to git master allows me to complete the original conversion process without throwing an error at the 2GB limit.

Many thanks,

Mark.