Received: from eggs.gnu.org ([2001:4830:134:3::10]:52927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbCCX-0006B7-Pq for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1VbCCS-0001pG-P4 for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:11497) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1VbCCS-0001p9-Gl for qemu-devel@nongnu.org; Tue, 29 Oct 2013 12:31:24 -0400 From: Kevin Wolf Date: Tue, 29 Oct 2013 17:30:57 +0100 Message-Id: <1383064269-27720-6-git-send-email-kwolf@redhat.com> In-Reply-To: <1383064269-27720-1-git-send-email-kwolf@redhat.com> References: <1383064269-27720-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 05/17] block/vpc: check that the image has not been truncated 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: 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 Reviewed-by: Eric Blake Signed-off-by: Kevin Wolf --- 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.8.1.4