Received: from eggs.gnu.org ([2001:4830:134:3::10]:52151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhNaU-0002hk-DP for qemu-devel@nongnu.org; Fri, 15 Nov 2013 12:53:50 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VhNaP-0004Bw-R5 for qemu-devel@nongnu.org; Fri, 15 Nov 2013 12:53:46 -0500 Received: from mx1.redhat.com ([209.132.183.28]:36460) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VhNaP-0004Br-JF for qemu-devel@nongnu.org; Fri, 15 Nov 2013 12:53:41 -0500 From: Kevin Wolf Date: Fri, 15 Nov 2013 18:53:15 +0100 Message-Id: <1384537999-5972-8-git-send-email-kwolf@redhat.com> In-Reply-To: <1384537999-5972-1-git-send-email-kwolf@redhat.com> References: <1384537999-5972-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 07/11] qcow2: fix possible corruption when reading multiple clusters List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: anthony@codemonkey.ws Cc: kwolf@redhat.com, qemu-devel@nongnu.org From: Peter Lieven if multiple sectors spanning multiple clusters are read the function count_contiguous_clusters should ensure that the cluster type should not change between the clusters. Especially the for-loop should break when we have one or more normal clusters followed by a compressed cluster. Unfortunately the wrong macro was used in the mask to compare the flags. This was discovered while debugging a data corruption issue when converting a compressed qcow2 image to raw. qemu-img reads 2MB chunks which span multiple clusters. CC: qemu-stable@nongnu.org Signed-off-by: Peter Lieven Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index f242244..791083a 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -290,7 +290,7 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size, uint64_t *l2_table, uint64_t stop_flags) { int i; - uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW2_CLUSTER_COMPRESSED; + uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED; uint64_t first_entry = be64_to_cpu(l2_table[0]); uint64_t offset = first_entry & mask; -- 1.8.1.4