Received: from eggs.gnu.org ([2001:4830:134:3::10]:33957) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgs9d-0002YX-Fv for qemu-devel@nongnu.org; Wed, 22 Oct 2014 05:24:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xgs9X-0003eW-Ab for qemu-devel@nongnu.org; Wed, 22 Oct 2014 05:24:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34745) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xgs9X-0003eS-2t for qemu-devel@nongnu.org; Wed, 22 Oct 2014 05:24:23 -0400 Date: Wed, 22 Oct 2014 11:24:18 +0200 From: Kevin Wolf Message-ID: <20141022092418.GE3188@noname.str.redhat.com> References: <1413965324-14541-1-git-send-email-mreitz@redhat.com> <1413965324-14541-9-git-send-email-mreitz@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1413965324-14541-9-git-send-email-mreitz@redhat.com> Subject: Re: [Qemu-devel] [PATCH v7 08/13] qcow2: Fix refcount blocks beyond image end List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Max Reitz Cc: qemu-devel@nongnu.org, Stefan Hajnoczi , =?iso-8859-1?Q?Beno=EEt?= Canet Am 22.10.2014 um 10:08 hat Max Reitz geschrieben: > If the qcow2 check function detects a refcount block located beyond the > image end, grow the image appropriately. This cannot break anything and > is the logical fix for such a case. > > Signed-off-by: Max Reitz > --- > block/qcow2-refcount.c | 63 ++++++++++++++++++++++++++++++++++++++++++++++---- > 1 file changed, 59 insertions(+), 4 deletions(-) > > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index d484029..3800d3c 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -1544,7 +1544,8 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res, > int64_t *nb_clusters) > { > BDRVQcowState *s = bs->opaque; > - int64_t i; > + int64_t i, size; > + int ret; > > for(i = 0; i < s->refcount_table_size; i++) { > uint64_t offset, cluster; > @@ -1560,9 +1561,63 @@ static int check_refblocks(BlockDriverState *bs, BdrvCheckResult *res, > } > > if (cluster >= *nb_clusters) { > - fprintf(stderr, "ERROR refcount block %" PRId64 > - " is outside image\n", i); > - res->corruptions++; > + fprintf(stderr, "%s refcount block %" PRId64 " is outside image\n", > + fix & BDRV_FIX_ERRORS ? "Repairing" : "ERROR", i); > + > + if (fix & BDRV_FIX_ERRORS) { > + int64_t old_nb_clusters = *nb_clusters; > + > + if (offset + s->cluster_size < offset || > + offset > INT64_MAX - s->cluster_size) Do you still need the first condition with the reworked second one? > + { > + ret = -EINVAL; > + goto resize_fail; > + } Kevin