Received: from eggs.gnu.org ([2001:4830:134:3::10]:59556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xyecd-00014z-9w for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XyecY-0008Sp-P4 for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:55 -0500 Received: from mx1.redhat.com ([209.132.183.28]:34770) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XyecY-0008Sh-HY for qemu-devel@nongnu.org; Wed, 10 Dec 2014 05:35:50 -0500 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sBAAZohB005387 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 10 Dec 2014 05:35:50 -0500 From: Kevin Wolf Date: Wed, 10 Dec 2014 11:34:37 +0100 Message-Id: <1418207679-32260-72-git-send-email-kwolf@redhat.com> In-Reply-To: <1418207679-32260-1-git-send-email-kwolf@redhat.com> References: <1418207679-32260-1-git-send-email-kwolf@redhat.com> Subject: [Qemu-devel] [PULL 71/73] vmdk: Check descriptor file length when reading it List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: kwolf@redhat.com From: Fam Zheng Since a too small file cannot be a valid VMDK image, and also since the buffer's first 4 bytes will be unconditionally examined by vmdk_open_sparse, let's error out the small file case to be clear. Signed-off-by: Fam Zheng Reviewed-by: Max Reitz Reviewed-by: Markus Armbruster Reviewed-by: Don Koch Message-id: 1417649314-13704-5-git-send-email-famz@redhat.com Signed-off-by: Max Reitz Signed-off-by: Kevin Wolf --- block/vmdk.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/block/vmdk.c b/block/vmdk.c index 5f43226..b703395 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -557,6 +557,14 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset, return NULL; } + if (size < 4) { + /* Both descriptor file and sparse image must be much larger than 4 + * bytes, also callers of vmdk_read_desc want to compare the first 4 + * bytes with VMDK4_MAGIC, let's error out if less is read. */ + error_setg(errp, "File is too small, not a valid image"); + return NULL; + } + size = MIN(size, (1 << 20) - 1); /* avoid unbounded allocation */ buf = g_malloc(size + 1); -- 1.8.3.1