mirror of
https://github.com/xemu-project/xemu.git
synced 2025-04-02 11:11:48 -04:00
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 <rjones@redhat.com> Signed-off-by: Fam Zheng <famz@redhat.com> Reviewed-by: Alberto Garcia <berto@igalia.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
b062ad86dc
commit
4a9c9ea0d3
1 changed files with 1 additions and 0 deletions
1
block.c
1
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue