]> Git Repo - qemu.git/commitdiff
qcow2: Avoid overflow in alloc_clusters_noref()
authorMax Reitz <[email protected]>
Tue, 29 Apr 2014 17:03:11 +0000 (19:03 +0200)
committerKevin Wolf <[email protected]>
Wed, 30 Apr 2014 12:46:13 +0000 (14:46 +0200)
alloc_clusters_noref() stores the cluster index in a uint64_t. However,
offsets are often represented as int64_t (as for example the return
value of alloc_clusters_noref() itself demonstrates). Therefore, we
should make sure all offsets in the allocated range of clusters are
representable using int64_t without overflows.

Signed-off-by: Max Reitz <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
block/qcow2-refcount.c

index a37ee45016f680862f83895a66a48aba5faf27ec..d2cb6a877563309e60c8dd95e5280b5bf087f3d6 100644 (file)
@@ -653,6 +653,13 @@ retry:
             goto retry;
         }
     }
+
+    /* Make sure that all offsets in the "allocated" range are representable
+     * in an int64_t */
+    if (s->free_cluster_index - 1 > (INT64_MAX >> s->cluster_bits)) {
+        return -EFBIG;
+    }
+
 #ifdef DEBUG_ALLOC2
     fprintf(stderr, "alloc_clusters: size=%" PRId64 " -> %" PRId64 "\n",
             size,
This page took 0.028156 seconds and 4 git commands to generate.