Received: from eggs.gnu.org ([2001:4830:134:3::10]:45118) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vi3Bf-0004qi-0F for qemu-devel@nongnu.org; Sun, 17 Nov 2013 09:19:00 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Vi3BZ-0005YZ-0l for qemu-devel@nongnu.org; Sun, 17 Nov 2013 09:18:54 -0500 Received: from mx1.redhat.com ([209.132.183.28]:16972) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Vi3BY-0005YS-P2 for qemu-devel@nongnu.org; Sun, 17 Nov 2013 09:18:48 -0500 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id rAHEImcv019346 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Sun, 17 Nov 2013 09:18:48 -0500 From: Max Reitz Date: Sun, 17 Nov 2013 15:18:43 +0100 Message-Id: <1384697924-16918-4-git-send-email-mreitz@redhat.com> In-Reply-To: <1384697924-16918-1-git-send-email-mreitz@redhat.com> References: <1384697924-16918-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH 3/4] qcow2: Sanitize refcount table size List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Make sure there were no overflows when calculating the in-memory refcount table size from the number of its clusters in-file. Signed-off-by: Max Reitz --- block/qcow2.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/qcow2.c b/block/qcow2.c index 3e612a8..9c29e1a 100644 --- a/block/qcow2.c +++ b/block/qcow2.c @@ -558,6 +558,14 @@ static int qcow2_open(BlockDriverState *bs, QDict *options, int flags, s->refcount_table_size = header.refcount_table_clusters << (s->cluster_bits - 3); + if ((s->refcount_table_size >> (s->cluster_bits - 3)) != + header.refcount_table_clusters) + { + error_setg(errp, "Refcount table is too big"); + ret = -EINVAL; + goto fail; + } + /* read the level 1 table */ s->l1_size = header.l1_size; -- 1.8.4.2