Skip to contentSkip to conversation

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

PATCH Superseded Peter Lieven 2 participants 3 messages Oct 22, 2013 Block layer

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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).

---
 block/vpc.c |    7 +++++++
 1 file changed, 7 insertions(+)
block/vpc.c +7 -0
index 1acc1d4..921364e 100644
@@ -269,6 +269,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
             }
         }
 
+        if (s->free_data_block_offset > bdrv_getlength(bs->file)) {
+            ret = -EINVAL;
+            fprintf(stderr, "block-vpc: free_data_block_offset points after"
+                            "the end of file. the image has been truncated.\n");
+            goto fail;
+        }
+
         s->last_bitmap_offset = (int64_t) -1;
 
 #ifdef CACHE
Signature · 1 line
1.7.9.5
#1 lore raw
Quoted 13 lines · Peter Lieven

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

---
 block/vpc.c |    7 +++++++
 1 file changed, 7 insertions(+)
block/vpc.c +0 -0
index 1acc1d4..921364e 100644

block/vpc.c static int vpc_open(BlockDriverState *bs, QDict *options, int flags, · line 275

Quoted 7 lines
block/vpc.c +4 -0
@@ -269,6 +269,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
             }
         }
 
+        if (s->free_data_block_offset > bdrv_getlength(bs->file)) {
+            ret = -EINVAL;
+            fprintf(stderr, "block-vpc: free_data_block_offset points after"
+                            "the end of file. the image has been truncated.\n");

Why fprintf() instead of using the errp argument?

Also, s/afterthe/after the/; s/file\. the/file. The/

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#2 lore raw
Quoted 17 lines · Eric Blake
Quoted 16 lines · Peter Lieven

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

---
  block/vpc.c |    7 +++++++
  1 file changed, 7 insertions(+)
block/vpc.c +0 -0
index 1acc1d4..921364e 100644
@@ -269,6 +269,13 @@ static int vpc_open(BlockDriverState *bs, QDict *options, int flags,
              }
          }
 
Quoted 5 lines

block/vpc.c static int vpc_open(BlockDriverState *bs, QDict *options, int flags, · line 275

Quoted 4 lines
block/vpc.c +4 -0
+        if (s->free_data_block_offset > bdrv_getlength(bs->file)) {
+            ret = -EINVAL;
+            fprintf(stderr, "block-vpc: free_data_block_offset points after"
+                            "the end of file. the image has been truncated.\n");

Why fprintf() instead of using the errp argument?

wasn't aware. a few lines earlier fprintf(stderr, ...) was used.

if the others are otherwise happy with the patch I will send a v2.

Peter