From 27539ac53154cf9da6990ce9bec1064d37cf2b1d Mon Sep 17 00:00:00 2001 From: Jeff Cody Date: Mon, 7 Aug 2017 08:38:20 -0400 Subject: block/vhdx: check for offset overflow to bdrv_truncate() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit VHDX uses uint64_t types for most offsets, following the VHDX spec. However, bdrv_truncate() takes an int64_t value for the truncating offset. Check for overflow before calling bdrv_truncate(). While we are here, replace the bit shifting with QEMU_ALIGN_UP as well. N.B.: For a compliant image this is not an issue, as the maximum VHDX image size is defined per the spec to be 64TB. Reviewed-by: Eric Blake Reviewed-by: Kevin Wolf Signed-off-by: Jeff Cody Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Kevin Wolf --- block/vhdx.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'block/vhdx.c') diff --git a/block/vhdx.c b/block/vhdx.c index 37224b8..7ae4589 100644 --- a/block/vhdx.c +++ b/block/vhdx.c @@ -1177,6 +1177,9 @@ static int vhdx_allocate_block(BlockDriverState *bs, BDRVVHDXState *s, /* per the spec, the address for a block is in units of 1MB */ *new_offset = ROUND_UP(*new_offset, 1024 * 1024); + if (*new_offset > INT64_MAX) { + return -EINVAL; + } return bdrv_truncate(bs->file, *new_offset + s->block_size, PREALLOC_MODE_OFF, NULL); -- cgit v1.1