From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:38712) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R37KD-00025K-0M for qemu-devel@nongnu.org; Mon, 12 Sep 2011 10:17:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R37KB-0007Cy-3V for qemu-devel@nongnu.org; Mon, 12 Sep 2011 10:17:28 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35912) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R37KA-0007Co-IR for qemu-devel@nongnu.org; Mon, 12 Sep 2011 10:17:26 -0400 From: Kevin Wolf Date: Mon, 12 Sep 2011 16:19:34 +0200 Message-Id: <1315837174-15327-36-git-send-email-kwolf@redhat.com> In-Reply-To: <1315837174-15327-1-git-send-email-kwolf@redhat.com> References: <1315837174-15327-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PATCH 35/35] qcow2: fix range check 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: Frediano Ziglio QCowL2Meta::offset is not cluster aligned but only sector aligned however nb_clusters count cluster from cluster start. This fix range check. Note that old code have no corruption issues related to this check cause it only cause intersection to occur when shouldn't. Signed-off-by: Frediano Ziglio Signed-off-by: Kevin Wolf --- block/qcow2-cluster.c | 14 +++++++------- 1 files changed, 7 insertions(+), 7 deletions(-) diff --git a/block/qcow2-cluster.c b/block/qcow2-cluster.c index 428b5ad..2f76311 100644 --- a/block/qcow2-cluster.c +++ b/block/qcow2-cluster.c @@ -776,17 +776,17 @@ again: */ QLIST_FOREACH(old_alloc, &s->cluster_allocs, next_in_flight) { - uint64_t end_offset = offset + nb_clusters * s->cluster_size; - uint64_t old_offset = old_alloc->offset; - uint64_t old_end_offset = old_alloc->offset + - old_alloc->nb_clusters * s->cluster_size; + uint64_t start = offset >> s->cluster_bits; + uint64_t end = start + nb_clusters; + uint64_t old_start = old_alloc->offset >> s->cluster_bits; + uint64_t old_end = old_start + old_alloc->nb_clusters; - if (end_offset < old_offset || offset > old_end_offset) { + if (end < old_start || start > old_end) { /* No intersection */ } else { - if (offset < old_offset) { + if (start < old_start) { /* Stop at the start of a running allocation */ - nb_clusters = (old_offset - offset) >> s->cluster_bits; + nb_clusters = old_start - start; } else { nb_clusters = 0; } -- 1.7.6