qcow2-refcount: Sanitize refcount table entry
authorMax Reitz <mreitz@redhat.com>
Fri, 7 Mar 2014 22:10:12 +0000 (23:10 +0100)
committerStefan Hajnoczi <stefanha@redhat.com>
Thu, 13 Mar 2014 13:23:27 +0000 (14:23 +0100)
When reading the refcount table entry in get_refcount(), only bits which
are actually significant for the refcount block offset should be taken
into account.

Signed-off-by: Max Reitz <mreitz@redhat.com>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
block/qcow2-refcount.c

index 8712d8bd549d70df987e54052cabab5d4734b857..6151148507b13135ebf469929b14ef55a0630ee1 100644 (file)
@@ -96,7 +96,8 @@ static int get_refcount(BlockDriverState *bs, int64_t cluster_index)
     refcount_table_index = cluster_index >> (s->cluster_bits - REFCOUNT_SHIFT);
     if (refcount_table_index >= s->refcount_table_size)
         return 0;
-    refcount_block_offset = s->refcount_table[refcount_table_index];
+    refcount_block_offset =
+        s->refcount_table[refcount_table_index] & REFT_OFFSET_MASK;
     if (!refcount_block_offset)
         return 0;