block: Fix error code for bdrv_getlength when the image is too big
v2 cover block: Fix error code for bdrv_getlength when the image is too big
v2: Correct detection of overflow. [Markus, Berto]
If the image has a huge enough virtual size,
$ qemu-img info afl9.img qemu-img: Can't get size of device 'image': Unknown error -512
It's because of the multiplication overflow in the return statement in bdrv_getlength (the big nagetive value is later truncated to 0x200). Fix it to return -EFBIG:
qemu-img: Can't get size of device 'image': File too large
Bug reported by Richard Jones in:
https://bugzilla.redhat.com/show_bug.cgi?id=1221499
Fam Zheng (2):
block: Detect multiplication overflow in bdrv_getlength
qemu-iotests: qemu-img info on afl VMDK image with a huge capacity
block.c | 1 + tests/qemu-iotests/059 | 5 +++++ tests/qemu-iotests/059.out | 3 +++ tests/qemu-iotests/sample_images/afl9.vmdk.bz2 | Bin 0 -> 178 bytes 4 files changed, 9 insertions(+) create mode 100644 tests/qemu-iotests/sample_images/afl9.vmdk.bz2
Signature · 1 line
2.4.0
PATCH v2 1/2 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.
--- block.c | 1 + 1 file changed, 1 insertion(+)
block.c +1 -0
@@ -2330,6 +2330,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 ; }
Signature · 1 line
2.4.0
Re: [Qemu-devel] [PATCH v2 1/2] block: Detect multiplication overflow in bdrv_getlength
Quoted 6 lines · Fam Zheng
Bogus image may have a large
total_sectorsthat will overflow the multiplication. For cleanness, fix the return code so the error message will be meaningful.Reported-by Richard W.M. Jones <[email protected]>Signed-off-by Fam Zheng <[email protected]>
Berto
PATCH v2 2/2 qemu-iotests: qemu-img info on afl VMDK image with a huge capacity
In reply to Fam ZhengThe image is contributed by Richard W.M. Jones.
--- tests/qemu-iotests/059 | 5 +++++ tests/qemu-iotests/059.out | 3 +++ tests/qemu-iotests/sample_images/afl9.vmdk.bz2 | Bin 0 -> 178 bytes 3 files changed, 8 insertions(+) create mode 100644 tests/qemu-iotests/sample_images/afl9.vmdk.bz2
tests/qemu-iotests/059 +5 -0
@@ -132,6 +132,11 @@ _img_info $QEMU_IO -c "write -P 0xa 900G 512" "$TEST_IMG" | _filter_qemu_io $QEMU_IO -c "read -v 900G 1024" "$TEST_IMG" | _filter_qemu_io +echo +echo "=== Testing afl image with a very large capacity ===" +_use_sample_img afl9.vmdk.bz2 +_img_info + # success, all done echo "*** done" rm -f $seq.full
tests/qemu-iotests/059.out +3 -0
@@ -2336,4 +2336,7 @@ e1000003e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ e1000003f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................ read 1024/1024 bytes at offset 966367641600 1 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +=== Testing afl image with a very large capacity === +qemu-img: Can't get size of device 'image': File too large *** done
tests/qemu-iotests/sample_images/afl9.vmdk.bz2 new file binary +0 -0
Signature · 1 line
2.4.0
Quoted 11 lines · Fam Zheng
v2: Correct detection of overflow. [Markus, Berto]
If the image has a huge enough virtual size,
$ qemu-img info afl9.img qemu-img: Can't get size of device 'image': Unknown error -512It's because of the multiplication overflow in the return statement in
bdrv_getlength(the big nagetive value is later truncated to0x200). Fix it to return-EFBIG:
Quoted 5 lines
qemu-img: Can't get size of device 'image': File too large
Bug reported by Richard Jones in:
Series
Kevin Wolf
AppliedAm 15.05.2015 um 10:36 hat Fam Zheng geschrieben:
Quoted 11 lines
v2: Correct detection of overflow. [Markus, Berto]
If the image has a huge enough virtual size,
$ qemu-img info afl9.img qemu-img: Can't get size of device 'image': Unknown error -512It's because of the multiplication overflow in the return statement in
bdrv_getlength(the big nagetive value is later truncated to0x200). Fix it to return-EFBIG:
Quoted 5 lines
qemu-img: Can't get size of device 'image': File too large
Bug reported by Richard Jones in:
Thanks, applied to the block branch.
Kevin