Patchwork [PULL,05/30] block/vpc: check that the image has not been truncated

login
register
mail settings
Submitter Kevin Wolf
Date Oct. 31, 2013, 3:48 p.m.
Message ID <1383234524-372-6-git-send-email-kwolf@redhat.com>
Download mbox | patch
Permalink /patch/287521/
State New
Headers show

Comments

Kevin Wolf - Oct. 31, 2013, 3:48 p.m.
From: Peter Lieven <pl@kamp.de>

this adds a check that a dynamic VHD file has not been
accidently truncated (e.g. during transfer or upload).

Signed-off-by: Peter Lieven <pl@kamp.de>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 block/vpc.c | 7 +++++++
 1 file changed, 7 insertions(+)

Patch

diff --git a/block/vpc.c b/block/vpc.c
index b5dca39..627d11c 100644
--- a/block/vpc.c
+++ b/block/vpc.c
@@ -260,6 +260,13 @@  static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
             }
         }
 
+        if (s->free_data_block_offset > bdrv_getlength(bs->file)) {
+            error_setg(errp, "block-vpc: free_data_block_offset points after "
+                             "the end of file. The image has been truncated.");
+            ret = -EINVAL;
+            goto fail;
+        }
+
         s->last_bitmap_offset = (int64_t) -1;
 
 #ifdef CACHE