From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47141) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XvzJU-0002E1-1B for qemu-devel@nongnu.org; Tue, 02 Dec 2014 21:05:14 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XvzJN-0002qT-Ts for qemu-devel@nongnu.org; Tue, 02 Dec 2014 21:05:07 -0500 Received: from mx1.redhat.com ([209.132.183.28]:56660) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XvzJN-0002oi-KN for qemu-devel@nongnu.org; Tue, 02 Dec 2014 21:05:01 -0500 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id sB3251Om015578 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Tue, 2 Dec 2014 21:05:01 -0500 From: Fam Zheng Date: Wed, 3 Dec 2014 10:05:12 +0800 Message-Id: <1417572314-5504-5-git-send-email-famz@redhat.com> In-Reply-To: <1417572314-5504-1-git-send-email-famz@redhat.com> References: <1417572314-5504-1-git-send-email-famz@redhat.com> Subject: [Qemu-devel] [PATCH for-2.3 v2 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 , Markus Armbruster , Stefan Hajnoczi 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: Markus Armbruster --- block/vmdk.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/block/vmdk.c b/block/vmdk.c index e863a09..b051adc 100644 --- a/block/vmdk.c +++ b/block/vmdk.c @@ -557,6 +557,11 @@ static char *vmdk_read_desc(BlockDriverState *file, uint64_t desc_offset, return NULL; } + if (size < 4) { + error_setg_errno(errp, -size, "File is too small, not a valid image"); + return NULL; + } + size = MIN(size, 1 << 20); /* avoid unbounded allocation */ buf = g_malloc(size); -- 1.9.3