Skip to content

Commit 175117c

Browse files
XanClicmdroth
authored andcommitted
qcow2: Prevent numerical overflow
In qcow2_alloc_cluster_offset(), *num is limited to INT_MAX >> BDRV_SECTOR_BITS by all callers. However, since remaining is of type uint64_t, we might as well cast *num to that type before performing the shift. Cc: [email protected] Signed-off-by: Max Reitz <[email protected]> Reviewed-by: Kevin Wolf <[email protected]> Signed-off-by: Kevin Wolf <[email protected]> (cherry picked from commit 11c8976) Signed-off-by: Michael Roth <[email protected]>
1 parent aa58eed commit 175117c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

block/qcow2-cluster.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,7 @@ int qcow2_alloc_cluster_offset(BlockDriverState *bs, uint64_t offset,
12021202

12031203
again:
12041204
start = offset;
1205-
remaining = *num << BDRV_SECTOR_BITS;
1205+
remaining = (uint64_t)*num << BDRV_SECTOR_BITS;
12061206
cluster_offset = 0;
12071207
*host_offset = 0;
12081208
cur_bytes = 0;

0 commit comments

Comments
 (0)