From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39991) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4ux8-0001d3-CS for qemu-devel@nongnu.org; Sun, 19 Jan 2014 11:10:31 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1W4ux3-0007pb-HK for qemu-devel@nongnu.org; Sun, 19 Jan 2014 11:10:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:30352) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1W4ux3-0007pI-9O for qemu-devel@nongnu.org; Sun, 19 Jan 2014 11:10:21 -0500 Message-ID: <52DBF958.7090107@redhat.com> Date: Sun, 19 Jan 2014 17:12:08 +0100 From: Max Reitz MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1 2/3] qcow2: fix offset overflow List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hu Tao , qemu-devel@nongnu.org Cc: Kevin Wolf , Stefan Hajnoczi On 30.12.2013 06:29, Hu Tao wrote: > When cluster size is big enough it can lead offset overflow > in qcow2_alloc_clusters_at(). This patch fixes it. > > Signed-off-by: Hu Tao > --- > block/qcow2-refcount.c | 7 ++++++- > 1 file changed, 6 insertions(+), 1 deletion(-) > > diff --git a/block/qcow2-refcount.c b/block/qcow2-refcount.c > index c974abe..b3ebb7f 100644 > --- a/block/qcow2-refcount.c > +++ b/block/qcow2-refcount.c > @@ -676,7 +676,12 @@ int qcow2_alloc_clusters_at(BlockDriverState *bs, uint64_t offset, > BDRVQcowState *s = bs->opaque; > uint64_t cluster_index; > uint64_t old_free_cluster_index; > - int i, refcount, ret; > + uint64_t i; > + int refcount, ret; > + > + if (nb_clusters <= 0) { > + return 0; I think I'd rather return -EINVAL here. > + } > > /* Check how many clusters there are free */ > cluster_index = offset >> s->cluster_bits;