From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58436) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwJLu-0008Ey-54 for qemu-devel@nongnu.org; Wed, 03 Dec 2014 18:29:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XwJLl-00087a-IY for qemu-devel@nongnu.org; Wed, 03 Dec 2014 18:28:58 -0500 Received: from mx1.redhat.com ([209.132.183.28]:58626) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XwJLl-00087T-AS for qemu-devel@nongnu.org; Wed, 03 Dec 2014 18:28:49 -0500 From: Fam Zheng Date: Thu, 4 Dec 2014 07:28:32 +0800 Message-Id: <1417649314-13704-5-git-send-email-famz@redhat.com> In-Reply-To: <1417649314-13704-1-git-send-email-famz@redhat.com> References: <1417649314-13704-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH v4 4/6] 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: Kevin Wolf , Don Koch , Markus Armbruster , Stefan Hajnoczi , Max Reitz 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 --- 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.9.3