]> rtime.felk.cvut.cz Git - lisovros/qemu_apohw.git/commitdiff
block/vpc: check that the image has not been truncated
authorPeter Lieven <pl@kamp.de>
Thu, 24 Oct 2013 07:16:03 +0000 (09:16 +0200)
committerKevin Wolf <kwolf@redhat.com>
Thu, 24 Oct 2013 15:34:48 +0000 (17:34 +0200)
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

index b5dca3961e609d40d502fe84838698859de32cd9..627d11cb9b9a20108be22d464a53f03a26b6837c 100644 (file)
@@ -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