Skip to contentSkip to conversation

qcow2-refcount: Catch array overflow

PATCH New Max Reitz 1 participant 1 message Sep 20, 2013 Block layer

lore
Share & tools
lore

Max Reitz

author
#0 lore raw

PATCH 1/1 qcow2-refcount: Catch array overflow

Add an assertion to alloc_refcount_block which catches an array index being out of bounds; this may occur if cluster_index is much too high (exceeding the image size). This in turn can be caused for instance by snapshotting a corrupted image (i.e., corrupted L2 tables).

---
 block/qcow2-refcount.c | 1 +
 1 file changed, 1 insertion(+)
block/qcow2-refcount.c +1 -0
index 4264148..80da2ff 100644
@@ -341,6 +341,7 @@ static int alloc_refcount_block(BlockDriverState *bs,
     /* Fill the new refcount table */
     memcpy(new_table, s->refcount_table,
         s->refcount_table_size * sizeof(uint64_t));
+    assert(refcount_table_index < table_size);
     new_table[refcount_table_index] = new_block;
 
     int i;
Signature · 1 line
1.8.3.1