Skip to content

Commit

Permalink
qcow2: fix possible corruption when reading multiple clusters
Browse files Browse the repository at this point in the history
if multiple sectors spanning multiple clusters are read the
function count_contiguous_clusters should ensure that the
cluster type should not change between the clusters.

Especially the for-loop should break when we have one
or more normal clusters followed by a compressed cluster.

Unfortunately the wrong macro was used in the mask to
compare the flags.

This was discovered while debugging a data corruption
issue when converting a compressed qcow2 image to raw.
qemu-img reads 2MB chunks which span multiple clusters.

CC: [email protected]
Signed-off-by: Peter Lieven <[email protected]>
Signed-off-by: Kevin Wolf <[email protected]>
  • Loading branch information
plieven authored and kevmw committed Nov 14, 2013
1 parent 968854c commit 78a52ad
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion block/qcow2-cluster.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static int count_contiguous_clusters(uint64_t nb_clusters, int cluster_size,
uint64_t *l2_table, uint64_t stop_flags)
{
int i;
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW2_CLUSTER_COMPRESSED;
uint64_t mask = stop_flags | L2E_OFFSET_MASK | QCOW_OFLAG_COMPRESSED;
uint64_t first_entry = be64_to_cpu(l2_table[0]);
uint64_t offset = first_entry & mask;

Expand Down

0 comments on commit 78a52ad

Please sign in to comment.