qemu/block
Max Reitz c834cba905 qcow2: Fix qcow2_get_cluster_offset()
Recently, qcow2_get_cluster_offset() has been changed to work with bytes
instead of sectors. This invalidated some assertions and introduced a
possible integer multiplication overflow.

This could be reproduced using e.g.

$ qemu-img create -f qcow2 -o cluster_size=1M blub.qcow2 8G
Formatting 'foo.qcow2', fmt=qcow2 size=8589934592 encryption=off
cluster_size=1048576 lazy_refcounts=off refcount_bits=16
$ qemu-io -c map blub.qcow2
qemu-io: qemu/block/qcow2-cluster.c:504: qcow2_get_cluster_offset:
Assertion `bytes_needed <= INT_MAX' failed.
[1]    20775 abort (core dumped)  qemu-io -c map foo.qcow2

This patch removes the now wrong assertion, adding comments and more
assertions to prove its correctness (and fixing the overflow which would
become apparent with the original assertion removed).

Signed-off-by: Max Reitz <mreitz@redhat.com>
Message-id: 20160620142623.24471-3-mreitz@redhat.com
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Max Reitz <mreitz@redhat.com>
2016-07-13 13:41:38 +02:00
..
accounting.c block: Clean up includes 2016-01-20 13:36:23 +01:00
archipelago.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
backup.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
blkdebug.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
blkreplay.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
blkverify.c block: Convert bdrv_aio_writev() to BdrvChild 2016-07-05 16:46:26 +02:00
block-backend.c block/qdev: Allow configuring rerror/werror with qdev properties 2016-07-13 13:32:27 +02:00
bochs.c block: Convert bdrv_co_preadv/pwritev to BdrvChild 2016-07-05 16:46:27 +02:00
cloop.c block: Convert bdrv_pread(v) to BdrvChild 2016-07-05 16:46:27 +02:00
commit.c commit: Fix use of error handling policy 2016-07-13 13:32:27 +02:00
crypto.c QAPI patches for 2016-07-06 2016-07-06 11:38:09 +01:00
curl.c block: always compile-check debug prints 2016-05-12 15:22:08 +02:00
dirty-bitmap.c include/qemu/osdep.h: Don't include qapi/error.h 2016-03-22 22:20:15 +01:00
dmg.c block: Convert bdrv_pread(v) to BdrvChild 2016-07-05 16:46:27 +02:00
gluster.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
io.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
iscsi.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
linux-aio.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
Makefile.objs block: Move bdrv_commit() to block/commit.c 2016-07-05 16:46:27 +02:00
mirror.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
nbd-client.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
nbd-client.h nbd: Simplify client FUA handling 2016-05-12 15:22:09 +02:00
nbd.c block: Switch discard length bounds to byte-based 2016-07-05 16:46:25 +02:00
nfs.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
null.c block/null: Implement bdrv_refresh_filename() 2016-06-16 15:20:37 +02:00
parallels.c block: Convert bdrv_pwrite_zeroes() to BdrvChild 2016-07-05 16:46:27 +02:00
qapi.c qapi: Add new visit_complete() function 2016-07-06 10:52:04 +02:00
qcow2-cache.c block: Convert bdrv_pwrite(v/_sync) to BdrvChild 2016-07-05 16:46:27 +02:00
qcow2-cluster.c qcow2: Fix qcow2_get_cluster_offset() 2016-07-13 13:41:38 +02:00
qcow2-refcount.c block/qcow2: Don't use cpu_to_*w() 2016-07-05 16:54:04 +02:00
qcow2-snapshot.c block: Convert bdrv_pwrite(v/_sync) to BdrvChild 2016-07-05 16:46:27 +02:00
qcow2.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
qcow2.h qcow2: Implement .bdrv_co_pwritev() 2016-06-16 15:19:55 +02:00
qcow.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
qed-check.c qed: Use DIV_ROUND_UP 2016-06-07 18:19:24 +03:00
qed-cluster.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-gencb.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-l2-cache.c block: Clean up includes 2016-01-20 13:36:23 +01:00
qed-table.c block: Convert bdrv_aio_writev() to BdrvChild 2016-07-05 16:46:26 +02:00
qed.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
qed.h util: move declarations out of qemu-common.h 2016-03-22 22:20:17 +01:00
quorum.c block: Convert bdrv_aio_writev() to BdrvChild 2016-07-05 16:46:26 +02:00
raw_bsd.c block: Convert bdrv_co_preadv/pwritev to BdrvChild 2016-07-05 16:46:27 +02:00
raw-aio.h raw-posix: Implement .bdrv_co_preadv/pwritev 2016-06-16 15:19:55 +02:00
raw-posix.c raw-posix: Use qemu_dup 2016-07-13 13:26:02 +02:00
raw-win32.c block: Move request_alignment into BlockLimit 2016-07-05 16:46:26 +02:00
rbd.c coccinelle: Remove unnecessary variables for function return value 2016-06-20 16:38:13 +02:00
sheepdog.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
snapshot.c error: Remove NULL checks on error_propagate() calls 2016-06-20 16:38:13 +02:00
ssh.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
stream.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
throttle-groups.c block: Move I/O throttling configuration functions to BlockBackend 2016-05-19 16:45:30 +02:00
trace-events trace: split out trace events for block/ directory 2016-06-20 17:22:14 +01:00
vdi.c block: Convert bdrv_co_preadv/pwritev to BdrvChild 2016-07-05 16:46:27 +02:00
vhdx-endian.c qemu-common: stop including qemu/bswap.h from qemu-common.h 2016-05-19 16:42:28 +02:00
vhdx-log.c block: Convert bdrv_pwrite(v/_sync) to BdrvChild 2016-07-05 16:46:27 +02:00
vhdx.c block: Convert bdrv_pwrite(v/_sync) to BdrvChild 2016-07-05 16:46:27 +02:00
vhdx.h block: vhdx - update PAYLOAD_BLOCK_UNMAPPED value to match 1.00 spec 2014-12-12 15:42:22 +00:00
vmdk.c coroutine: move entry argument to qemu_coroutine_create 2016-07-13 13:26:02 +02:00
vpc.c block: Convert bdrv_co_preadv/pwritev to BdrvChild 2016-07-05 16:46:27 +02:00
vvfat.c block: Convert bdrv_write() to BdrvChild 2016-07-05 16:46:27 +02:00
win32-aio.c block: Clean up includes 2016-01-20 13:36:23 +01:00
write-threshold.c block: Clean up includes 2016-01-20 13:36:23 +01:00