[PATCH] block/vmdk: prevent division by zero with zero cluster sectors

[email protected]
Newsgroups gmane.comp.emulators.qemu.block,gmane.comp.emulators.qemu
Message-ID <[email protected]>
From: Denis Rastyogin <[email protected]>

A zero cluster_sectors value passes the existing upper-bound check
and later causes a division-by-zero in get_cluster_offset().

UBSan reports:

../block/vmdk.c:1608:30: runtime error: division by zero
    #0 0x5562d3b3b63b in get_cluster_offset ../block/vmdk.c:1608
    #1 0x5562d3db9aa7 in vmdk_co_block_status ../block/vmdk.c:1796
    #2 0x5562d3c48bb3 in bdrv_co_do_block_status ../block/io.c:2494
    #3 0x5562d3c55a3d in bdrv_co_common_block_status_above ../block/io.c:2672
    #4 0x5562d3c5630e in bdrv_co_block_status_above ../block/io.c:2752
    #5 0x5562d3ec5a3d in bdrv_co_block_status_above_entry block/block-gen.c:386
    #6 0x5562d40ab573 in coroutine_trampoline ../util/coroutine-ucontext.c:175

Signed-off-by: Denis Rastyogin <[email protected]>
---
 block/vmdk.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/vmdk.c b/block/vmdk.c
index cd8b4ec7c8..7a7935b25a 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -537,7 +537,7 @@ static int vmdk_add_extent(BlockDriverState *bs,
     BDRVVmdkState *s = bs->opaque;
     int64_t nb_sectors;
 
-    if (cluster_sectors > 0x200000) {
+    if (cluster_sectors == 0 || cluster_sectors > 0x200000) {
         /* 0x200000 * 512Bytes = 1GB for one cluster is unrealistic */
         error_setg(errp, "Invalid granularity, image may be corrupt");
         return -EFBIG;
-- 
2.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.