summaryrefslogtreecommitdiffstats
path: root/block/vmdk.c
diff options
context:
space:
mode:
authorFam Zheng <famz@redhat.com>2014-12-04 07:28:32 +0800
committerKevin Wolf <kwolf@redhat.com>2014-12-10 10:31:21 +0100
commit03c3359dfc490eaf922f88955d6a8cc51a37ce92 (patch)
tree64bbd7d73f08dccbb1f5cc901543caa341fec9fa /block/vmdk.c
parent73b7bcad439e0edaced05049897090cc10d84b5b (diff)
downloadhqemu-03c3359dfc490eaf922f88955d6a8cc51a37ce92.zip
hqemu-03c3359dfc490eaf922f88955d6a8cc51a37ce92.tar.gz
vmdk: Check descriptor file length when reading it
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 <famz@redhat.com> Reviewed-by: Max Reitz <mreitz@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Reviewed-by: Don Koch <dkoch@verizon.com> Message-id: 1417649314-13704-5-git-send-email-famz@redhat.com Signed-off-by: Max Reitz <mreitz@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Diffstat (limited to 'block/vmdk.c')
-rw-r--r--block/vmdk.c8
1 files changed, 8 insertions, 0 deletions
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);
OpenPOWER on IntegriCloud