From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40848) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOrJF-0004d1-2M for qemu-devel@nongnu.org; Wed, 25 Sep 2013 11:47:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VOrJ6-0004mN-IF for qemu-devel@nongnu.org; Wed, 25 Sep 2013 11:47:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:60522) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VOrJ6-0004mH-Ae for qemu-devel@nongnu.org; Wed, 25 Sep 2013 11:47:16 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r8PFlEhE023907 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 25 Sep 2013 11:47:15 -0400 From: Max Reitz Date: Wed, 25 Sep 2013 17:47:12 +0200 Message-Id: <1380124032-20803-1-git-send-email-mreitz@redhat.com> Subject: [Qemu-devel] [PATCH] qcow2: count_contiguous_clusters and compression List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi , Max Reitz The function is not intended to be used on compressed clusters and will not work correctly, if used anyway, since L2E_OFFSET_MASK is not the right mask for determining the offset of compressed clusters. Therefore, assert that the first cluster is not compressed and always include the compression flag in the mask of significant flags, i.e., stop the search as soon as a compressed cluster occurs. Signed-off-by: Max Reitz --- block/qcow2-cluster.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 738ff73..d695a2b 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -281,12 +281,15 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size, uint64_t *l2_table, uint64_t start, uint64_t stop_flags) { int i; - uint64_t mask = stop_flags | L2E_OFFSET_MASK; - uint64_t offset = be64_to_cpu(l2_table[0]) & mask; + uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW2_CLUSTER_COMPRESSED; + uint64_t first_entry = be64_to_cpu(l2_table[0]); + uint64_t offset = first_entry & mask; if (!offset) return 0; + assert(qcow2_get_cluster_type(first_entry) != QCOW2_CLUSTER_COMPRESSED); + for (i = start; i < start + nb_clusters; i++) { uint64_t l2_entry = be64_to_cpu(l2_table[i]) & mask; if (offset + (uint64_t) i * cluster_size != l2_entry) { -- 1.8.3.1