OSDN Git Service

qcow2: Fix refcount table size calculation
authorKevin Wolf <kwolf@redhat.com>
Fri, 26 Oct 2012 14:33:32 +0000 (16:33 +0200)
committerKevin Wolf <kwolf@redhat.com>
Wed, 14 Nov 2012 17:19:21 +0000 (18:19 +0100)
A missing factor for the refcount table entry size in the calculation
could mean that too little memory was allocated for the in-memory
representation of the table, resulting in a buffer overflow.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Michael Tokarev <mjt@tls.msk.ru>
Tested-by: Michael Tokarev <mjt@tls.msk.ru>
block/qcow2-refcount.c

index 5e3f915..96224d1 100644 (file)
@@ -301,7 +301,8 @@ static int alloc_refcount_block(BlockDriverState *bs,
     uint64_t last_table_size;
     uint64_t blocks_clusters;
     do {
-        uint64_t table_clusters = size_to_clusters(s, table_size);
+        uint64_t table_clusters =
+            size_to_clusters(s, table_size * sizeof(uint64_t));
         blocks_clusters = 1 +
             ((table_clusters + refcount_block_clusters - 1)
             / refcount_block_clusters);