From: Peter Lieven <pl@kamp.de>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, codyprime@gmail.com, Peter Lieven <pl@kamp.de>,
qemu-devel@nongnu.org, mreitz@redhat.com,
Jan-Hendrik Frintrop <jhf@kamp.de>
Subject: [Qemu-devel] [PATCH] block/vhdx: add check for truncated image files
Date: Thu, 29 Aug 2019 15:36:15 +0200 [thread overview]
Message-ID: <20190829133615.29873-1-pl@kamp.de> (raw)
qemu is currently not able to detect truncated vhdx image files.
Add a basic check if all allocated blocks are reachable to vhdx_co_check.
Signed-off-by: Jan-Hendrik Frintrop <jhf@kamp.de>
Signed-off-by: Peter Lieven <pl@kamp.de>
---
block/vhdx.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)
diff --git a/block/vhdx.c b/block/vhdx.c
index 6a09d0a55c..4382b1375d 100644
--- a/block/vhdx.c
+++ b/block/vhdx.c
@@ -2068,10 +2068,29 @@ static int coroutine_fn vhdx_co_check(BlockDriverState *bs,
BdrvCheckMode fix)
{
BDRVVHDXState *s = bs->opaque;
+ VHDXSectorInfo sinfo;
+ int64_t file_size = bdrv_get_allocated_file_size(bs);
+ int64_t sector_num;
if (s->log_replayed_on_open) {
result->corruptions_fixed++;
}
+
+ for (sector_num = 0; sector_num < bs->total_sectors;
+ sector_num += s->block_size / BDRV_SECTOR_SIZE) {
+ int nb_sectors = MIN(bs->total_sectors - sector_num,
+ s->block_size / BDRV_SECTOR_SIZE);
+ vhdx_block_translate(s, sector_num, nb_sectors, &sinfo);
+ if ((s->bat[sinfo.bat_idx] & VHDX_BAT_STATE_BIT_MASK) ==
+ PAYLOAD_BLOCK_FULLY_PRESENT) {
+ if (sinfo.file_offset +
+ sinfo.sectors_avail * BDRV_SECTOR_SIZE > file_size) {
+ /* block is past the end of file, image has been truncated. */
+ result->corruptions++;
+ }
+ }
+ }
+
return 0;
}
--
2.17.1
next reply other threads:[~2019-08-29 13:38 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-29 13:36 Peter Lieven [this message]
2019-09-02 13:07 ` [Qemu-devel] [PATCH] block/vhdx: add check for truncated image files Kevin Wolf
2019-09-02 13:15 ` Peter Lieven
2019-09-02 13:46 ` Kevin Wolf
2019-09-02 14:17 ` Peter Lieven
2019-09-02 14:31 ` Kevin Wolf
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190829133615.29873-1-pl@kamp.de \
--to=pl@kamp.de \
--cc=codyprime@gmail.com \
--cc=jhf@kamp.de \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.