From patchwork Mon Sep 15 02:32:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fam Zheng X-Patchwork-Id: 389179 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 75F86140088 for ; Mon, 15 Sep 2014 12:33:13 +1000 (EST) Received: from localhost ([::1]:56909 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTM6J-0006fy-LE for incoming@patchwork.ozlabs.org; Sun, 14 Sep 2014 22:33:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60618) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTM60-0006OG-Ab for qemu-devel@nongnu.org; Sun, 14 Sep 2014 22:32:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XTM5v-0001KL-67 for qemu-devel@nongnu.org; Sun, 14 Sep 2014 22:32:52 -0400 Received: from mx1.redhat.com ([209.132.183.28]:10000) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XTM5u-0001KG-TM for qemu-devel@nongnu.org; Sun, 14 Sep 2014 22:32:47 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s8F2WjFS022435 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Sun, 14 Sep 2014 22:32:46 -0400 Received: from fam-t430.nay.redhat.com (dhcp-14-161.nay.redhat.com [10.66.14.161]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s8F2Wgtj025669; Sun, 14 Sep 2014 22:32:43 -0400 From: Fam Zheng To: qemu-devel@nongnu.org Date: Mon, 15 Sep 2014 10:32:37 +0800 Message-Id: <1410748357-16049-1-git-send-email-famz@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Subject: [Qemu-devel] [PATCH v2] vmdk: Fix integer overflow in offset calculation X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 Reviewed-by: Max Reitz --- block/vmdk.c | 2 +- tests/qemu-iotests/005 | 10 +++++++++- tests/qemu-iotests/005.out | 10 +++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) 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/005 b/tests/qemu-iotests/005 index ba1236d..fc8944c 100755 --- a/tests/qemu-iotests/005 +++ b/tests/qemu-iotests/005 @@ -59,7 +59,7 @@ fi echo echo "creating large image" -_make_test_img 5000G +_make_test_img 16T echo echo "small read" @@ -69,6 +69,14 @@ echo echo "small write" $QEMU_IO -c "write 8192 4096" "$TEST_IMG" | _filter_qemu_io +echo +echo "small read at high offset" +$QEMU_IO -c "read 4T 4096" "$TEST_IMG" | _filter_qemu_io + +echo +echo "small write at high offset" +$QEMU_IO -c "write 4T 4096" "$TEST_IMG" | _filter_qemu_io + # success, all done echo "*** done" rm -f $seq.full diff --git a/tests/qemu-iotests/005.out b/tests/qemu-iotests/005.out index 2d3e7df..fd6aed9 100644 --- a/tests/qemu-iotests/005.out +++ b/tests/qemu-iotests/005.out @@ -1,7 +1,7 @@ QA output created by 005 creating large image -Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=5368709120000 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=17592186044416 small read read 4096/4096 bytes at offset 1024 @@ -10,4 +10,12 @@ read 4096/4096 bytes at offset 1024 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