Skip to contentSkip to conversation

block/vpc: check that the image has not been truncated

PATCH Applied Peter Lieven 3 participants 4 messages Oct 24, 2013 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 block/vpc: check that the image has not been truncated

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

---
v1->v2: used the errp argument as Eric suggested

 block/vpc.c |    7 +++++++
 1 file changed, 7 insertions(+)
block/vpc.c +7 -0
index b5dca39..627d11c 100644
@@ -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
Signature · 1 line
1.7.9.5
Reviewed-by on v2 1/1
#1 lore raw
Quoted 9 lines · Peter Lieven

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

---
v1->v2: used the errp argument as Eric suggested

 block/vpc.c |    7 +++++++
 1 file changed, 7 insertions(+)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw
Quoted 6 lines · Kevin Wolf

Am 24.10.2013 um 09:16 hat Peter Lieven geschrieben:

Quoted 4 lines

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

Thanks, applied to the block branch.

Can you have a look at:
block/vpc: fix virtual size for images created with disk2vhd

as well please.

Peter