aboutsummaryrefslogtreecommitdiff
path: root/block-qcow2.c
diff options
context:
space:
mode:
authoraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-04-05 17:40:38 +0000
committeraliguori <aliguori@c046a42c-6fe2-441c-8c8c-71466251a162>2009-04-05 17:40:38 +0000
commitf8de16605cf9864e258d91e95be0ed76bdeac744 (patch)
treea00cc31f460a29506c50ff47d25fbcaf8d90480e /block-qcow2.c
parente68b98dc7237d76fdef5c5d403d0613b443102da (diff)
Fix (at least one cause of) qcow2 corruption. (Nolan Leake)
qcow2's get_cluster_offset() scans forward in the l2 table to find other clusters that have the same allocation status as the first cluster. This is used by (among others) qcow_is_allocated(). Unfortunately, it was not checking to be sure that it didn't fall off the end of the l2 table. This patch adds that check. The symptom that motivated me to look into this was that bdrv_is_allocated() was returning false when there was in fact data there. This is one of many ways this bug could lead to data corruption. I checked the other place that scans for consecutive unallocated blocks (alloc_cluster_offset()) and it appears to be OK: nb_clusters = MIN(nb_clusters, s->l2_size - l2_index); appears to prevent the same problem from occurring. Signed-off-by: Nolan Leake <nolan <at> sigbus.net> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6977 c046a42c-6fe2-441c-8c8c-71466251a162
Diffstat (limited to 'block-qcow2.c')
-rw-r--r--block-qcow2.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/block-qcow2.c b/block-qcow2.c
index 60d87a4b8d..0e507ca480 100644
--- a/block-qcow2.c
+++ b/block-qcow2.c
@@ -761,6 +761,10 @@ static uint64_t get_cluster_offset(BlockDriverState *bs,
nb_available = (nb_available >> 9) + index_in_cluster;
+ if (nb_needed > nb_available) {
+ nb_needed = nb_available;
+ }
+
cluster_offset = 0;
/* seek the the l2 offset in the l1 table */