From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:55597) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoDY2-0002UK-Kk for qemu-devel@nongnu.org; Wed, 04 Dec 2013 09:35:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VoDXf-0003CB-LU for qemu-devel@nongnu.org; Wed, 04 Dec 2013 09:35:30 -0500 Received: from e7.ny.us.ibm.com ([32.97.182.137]:58908) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VoDXf-0003Bc-GP for qemu-devel@nongnu.org; Wed, 04 Dec 2013 09:35:07 -0500 Received: from /spool/local by e7.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 4 Dec 2013 09:35:07 -0500 From: Michael Roth Date: Wed, 4 Dec 2013 08:34:31 -0600 Message-Id: <1386167679-13021-25-git-send-email-mdroth@linux.vnet.ibm.com> In-Reply-To: <1386167679-13021-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1386167679-13021-1-git-send-email-mdroth@linux.vnet.ibm.com> Subject: [Qemu-devel] [PATCH 24/32] qcow2: count_contiguous_clusters and compression List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org From: 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 Signed-off-by: Kevin Wolf (cherry picked from commit 15684a474286cc2c6106c756ddd095a21d058970) Signed-off-by: Michael Roth --- 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 cca76d4..fd3054b 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -266,12 +266,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.7.9.5