diff mbox

[for-2.3,4/6] vmdk: Check descriptor file length when reading it

Message ID 1417505957-2666-5-git-send-email-famz@redhat.com
State New
Headers show

Commit Message

Fam Zheng Dec. 2, 2014, 7:39 a.m. UTC
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>
---
 block/vmdk.c | 5 +++++
 1 file changed, 5 insertions(+)
diff mbox

Patch

diff --git a/block/vmdk.c b/block/vmdk.c
index 0c5769c..f7c7979 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);