Received: from eggs.gnu.org ([2001:4830:134:3::10]:50892) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMxjh-0003mX-Ny for qemu-devel@nongnu.org; Fri, 20 Sep 2013 06:14:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VMxjb-0004jf-Ou for qemu-devel@nongnu.org; Fri, 20 Sep 2013 06:14:53 -0400 Received: from mx1.redhat.com ([209.132.183.28]:7750) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VMxjb-0004ja-Gs for qemu-devel@nongnu.org; Fri, 20 Sep 2013 06:14:47 -0400 Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8KAEkwW018633 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 20 Sep 2013 06:14:46 -0400 From: Max Reitz Date: Fri, 20 Sep 2013 12:14:44 +0200 Message-Id: <1379672084-21840-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH] qcow2-refcount: Catch array overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz Add an assertion to alloc_refcount_block which catches an array index being out of bounds; this may occur if cluster_index is much too high (exceeding the image size). This in turn can be caused for instance by snapshotting a corrupted image (i.e., corrupted L2 tables). Signed-off-by: Max Reitz --- block/qcow2-refcount.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c index 4264148..80da2ff 100644 --- a/block/qcow2-refcount.c +++ b/block/qcow2-refcount.c @@ -341,6 +341,7 @@ static int alloc_refcount_block(BlockDriverState *bs, /* Fill the new refcount table */ memcpy(new_table, s->refcount_table, s->refcount_table_size * sizeof(uint64_t)); + assert(refcount_table_index < table_size); new_table[refcount_table_index] = new_block; int i; -- 1.8.3.1