From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40975) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSNVg-0003Bn-TI for qemu-devel@nongnu.org; Fri, 12 Sep 2014 05:51:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XSNVb-0007fd-PN for qemu-devel@nongnu.org; Fri, 12 Sep 2014 05:51:20 -0400 Received: from mx1.redhat.com ([209.132.183.28]:5420) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XSNVb-0007fU-Hc for qemu-devel@nongnu.org; Fri, 12 Sep 2014 05:51:15 -0400 From: Fam Zheng Date: Fri, 12 Sep 2014 17:51:01 +0800 Message-Id: <1410515461-12740-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH] vmdk: Fix integer overflow in offset calculation List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Fam Zheng , Jeff Cody , Peter Lieven , Stefan Hajnoczi , Paolo Bonzini 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 Reported-by: Mark Cave-Ayland Signed-off-by: Fam Zheng --- block/vmdk.c | 2 +- tests/qemu-iotests/059 | 6 ++++++ tests/qemu-iotests/059.out | 7 +++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/block/vmdk.c b/block/vmdk.c index a1cb911..3fd7738 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -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; diff --git a/tests/qemu-iotests/059 b/tests/qemu-iotests/059 index 3c053c2..6ed2a25 100755 --- a/tests/qemu-iotests/059 +++ b/tests/qemu-iotests/059 @@ -126,6 +126,12 @@ _img_info $QEMU_IO -c "write -P 0xa 900G 512" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -v 900G 1024" "$TEST_IMG" | _filter_qemu_io +echo +echo "=== Testing reading and writing at big offset ===" +_make_test_img 4T +$QEMU_IO -c "write -P 0xa 1T 1024" "$TEST_IMG" | _filter_qemu_io +$QEMU_IO -c "read -P 0xa 1T 1024" "$TEST_IMG" | _filter_qemu_io + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/059.out b/tests/qemu-iotests/059.out index 0dadba6..51c72a6 100644 --- a/tests/qemu-iotests/059.out +++ b/tests/qemu-iotests/059.out @@ -2332,4 +2332,11 @@ e1000003e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ e1000003f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ read 1024/1024 bytes at offset 966367641600 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=== Testing reading and writing at big offset === +Formatting 'TEST_DIR/iotest-version3.IMGFMT', fmt=IMGFMT size=4398046511104 +wrote 1024/1024 bytes at offset 1099511627776 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 1024/1024 bytes at offset 1099511627776 +1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) *** done -- 1.9.3