diff mbox series

[v9,03/12] parallels: Fix image_end_offset and data_end after out-of-image check

Message ID 20230131102736.2127945-4-alexander.ivanov@virtuozzo.com (mailing list archive)
State New, archived
Headers show
Series parallels: Refactor the code of images checks and fix a bug | expand

Commit Message

Alexander Ivanov Jan. 31, 2023, 10:27 a.m. UTC
Set data_end to the end of the last cluster inside the image. In such a
way we can be sure that corrupted offsets in the BAT can't affect on the
image size. If there are no allocated clusters set image_end_offset by
data_end.

Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
---
 block/parallels.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Denis V. Lunev Jan. 31, 2023, 1:43 p.m. UTC | #1
On 1/31/23 11:27, Alexander Ivanov wrote:
> Set data_end to the end of the last cluster inside the image. In such a
> way we can be sure that corrupted offsets in the BAT can't affect on the
> image size. If there are no allocated clusters set image_end_offset by
> data_end.
>
> Signed-off-by: Alexander Ivanov <alexander.ivanov@virtuozzo.com>
> ---
>   block/parallels.c | 8 +++++++-
>   1 file changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/block/parallels.c b/block/parallels.c
> index 436b36bbd9..2ed7cca249 100644
> --- a/block/parallels.c
> +++ b/block/parallels.c
> @@ -488,7 +488,13 @@ static int coroutine_fn parallels_co_check(BlockDriverState *bs,
>           }
>       }
>   
> -    res->image_end_offset = high_off + s->cluster_size;
> +    if (high_off == 0) {
> +        res->image_end_offset = s->data_end << BDRV_SECTOR_BITS;
> +    } else {
> +        res->image_end_offset = high_off + s->cluster_size;
> +        s->data_end = res->image_end_offset >> BDRV_SECTOR_BITS;
> +    }
> +
>       if (size > res->image_end_offset) {
>           int64_t count;
>           count = DIV_ROUND_UP(size - res->image_end_offset, s->cluster_size);
Reviewed-by: Denis V. Lunev <den@openvz.org>
diff mbox series

Patch

diff --git a/block/parallels.c b/block/parallels.c
index 436b36bbd9..2ed7cca249 100644
--- a/block/parallels.c
+++ b/block/parallels.c
@@ -488,7 +488,13 @@  static int coroutine_fn parallels_co_check(BlockDriverState *bs,
         }
     }
 
-    res->image_end_offset = high_off + s->cluster_size;
+    if (high_off == 0) {
+        res->image_end_offset = s->data_end << BDRV_SECTOR_BITS;
+    } else {
+        res->image_end_offset = high_off + s->cluster_size;
+        s->data_end = res->image_end_offset >> BDRV_SECTOR_BITS;
+    }
+
     if (size > res->image_end_offset) {
         int64_t count;
         count = DIV_ROUND_UP(size - res->image_end_offset, s->cluster_size);