From 4a9c9ea0d318bec2f67848c5ceaf4ad5bcb91d09 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Fri, 15 May 2015 16:36:05 +0800 Subject: [PATCH] block: Detect multiplication overflow in bdrv_getlength Bogus image may have a large total_sectors that will overflow the multiplication. For cleanness, fix the return code so the error message will be meaningful. Reported-by: Richard W.M. Jones Signed-off-by: Fam Zheng Reviewed-by: Alberto Garcia Reviewed-by: Markus Armbruster Signed-off-by: Kevin Wolf --- block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/block.c b/block.c index 325f7272fe..f42d70e791 100644 --- a/block.c +++ b/block.c @@ -2341,6 +2341,7 @@ int64_t bdrv_getlength(BlockDriverState *bs) { int64_t ret = bdrv_nb_sectors(bs); + ret = ret > INT64_MAX / BDRV_SECTOR_SIZE ? -EFBIG : ret; return ret < 0 ? ret : ret * BDRV_SECTOR_SIZE; }