qemu-img: fix division by zero in bench_cb() for zero-sized images
PATCH 1/1 qemu-img: fix division by zero in bench_cb() for zero-sized images
From: Denis Rastyogin <[email protected]>
This error was discovered by fuzzing qemu-img.
This commit fixes a division by zero error in the bench_cb() function that occurs when using the bench command with a zero-sized image.
The issue arises because b->image_size can be zero, leading to a division by zero in the modulo operation (b->offset %= b->image_size). This patch adds a check for b->image_size == 0 and resets b->offset to 0 in such cases, preventing the error.
--- qemu-img.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
qemu-img.c +5 -1
@@ -4488,7 +4488,11 @@ static void bench_cb(void *opaque, int ret)*/ b->in_flight++; b->offset += b->step; - b->offset %= b->image_size; +if (b->image_size ==0 ) { + b->offset =0 ; + }else { + b->offset %= b->image_size; + }if (b->write) { acb =blk_aio_pwritev (b->blk, offset, b->qiov,0 , bench_cb, b); }else {
Signature · 1 line
2.42.2
Kevin Wolf
AppliedAm 18.03.2025 um 11:19 hat [email protected] geschrieben:
Quoted 7 lines
From: Denis Rastyogin <[email protected]>
This error was discovered by fuzzing qemu-img.
This commit fixes a division by zero error in the
bench_cb()function that occurs when using the bench command with a zero-sized image.
Quoted 6 lines
The issue arises because
b->image_sizecan be zero, leading to a division by zero in the modulo operation (b->offset%=b->image_size). This patch adds a check forb->image_size== 0 and resetsb->offsetto 0 in such cases, preventing the error.Signed-off-by Denis Rastyogin <[email protected]>
Thanks, applied to the block branch.
Kevin