qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PULL 71/73] vmdk: Check descriptor file length when readin


From: Kevin Wolf
Subject: [Qemu-devel] [PULL 71/73] vmdk: Check descriptor file length when reading it
Date: Wed, 10 Dec 2014 11:34:37 +0100

From: Fam Zheng <address@hidden>

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 <address@hidden>
Reviewed-by: Max Reitz <address@hidden>
Reviewed-by: Markus Armbruster <address@hidden>
Reviewed-by: Don Koch <address@hidden>
Message-id: address@hidden
Signed-off-by: Max Reitz <address@hidden>
Signed-off-by: Kevin Wolf <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]