Received: from eggs.gnu.org ([2001:4830:134:3::10]:43486) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZFAA-0006Uw-59 for qemu-devel@nongnu.org; Thu, 24 Oct 2013 03:17:03 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VZFA2-00049H-7y for qemu-devel@nongnu.org; Thu, 24 Oct 2013 03:16:58 -0400 Received: from mx.ipv6.kamp.de ([2a02:248:0:51::16]:44870 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VZFA1-00048y-RW for qemu-devel@nongnu.org; Thu, 24 Oct 2013 03:16:50 -0400 From: Peter Lieven Date: Thu, 24 Oct 2013 09:16:03 +0200 Message-Id: <1382598963-9264-1-git-send-email-pl@kamp.de> Subject: [Qemu-devel] [PATCHv2] block/vpc: check that the image has not been truncated List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com, pbonzini@redhat.com, stefanha@redhat.com, Peter Lieven this adds a check that a dynamic VHD file has not been accidently truncated (e.g. during transfer or upload). Signed-off-by: Peter Lieven --- v1->v2: used the errp argument as Eric suggested block/vpc.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/block/vpc.c b/block/vpc.c index b5dca39..627d11c 100644 --- a/block/vpc.c +++ b/block/vpc.c @@ -260,6 +260,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags, } } + if (s->free_data_block_offset > bdrv_getlength(bs->file)) { + error_setg(errp, "block-vpc: free_data_block_offset points after " + "the end of file. The image has been truncated."); + ret = -EINVAL; + goto fail; + } + s->last_bitmap_offset = (int64_t) -1; #ifdef CACHE -- 1.7.9.5