From patchwork Tue Nov 12 12:48:07 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 290626 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id CABD72C00B1 for ; Tue, 12 Nov 2013 23:50:00 +1100 (EST) Received: from localhost ([::1]:42454 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgDPq-0005zh-Q3 for incoming@patchwork.ozlabs.org; Tue, 12 Nov 2013 07:49:58 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgDPX-0005zU-MN for qemu-devel@nongnu.org; Tue, 12 Nov 2013 07:49:44 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VgDPQ-0003by-EL for qemu-devel@nongnu.org; Tue, 12 Nov 2013 07:49:39 -0500 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:48712 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VgDPQ-0003bp-3P for qemu-devel@nongnu.org; Tue, 12 Nov 2013 07:49:32 -0500 Received: (qmail 15835 invoked by uid 89); 12 Nov 2013 12:49:30 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98/18100. hbedv: 8.2.12.140/7.11.113.6. spamassassin: 3.3.1. Clear:RC:1(82.141.1.145):SA:0(-1.2/4.0):. Processed in 1.298054 secs); 12 Nov 2013 12:49:30 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 12 Nov 2013 12:49:28 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id 8CF2020688; Tue, 12 Nov 2013 13:48:28 +0100 (CET) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id A33275FAA4; Tue, 12 Nov 2013 13:48:28 +0100 (CET) From: Peter Lieven To: qemu-devel@nongnu.org Date: Tue, 12 Nov 2013 13:48:07 +0100 Message-Id: <1384260487-5032-1-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, aliguori@us.ibm.com, Peter Lieven , qemu-stable@nongnu.org, mreitz@redhat.com, stefanha@redhat.com, pbonzini@redhat.com Subject: [Qemu-devel] [PATCH 1.7] qcow2: fix possible corruption when reading multiple clusters X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 --- 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 6d7d1ac..11f9c50 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;