From: Denis V. Lunev <[email protected]>

s->cluster_size comes from the image and qemu_blockalign() aborts when
the allocation cannot be satisfied, so use the try variant and report
the failure instead.

The two are not interchangeable: qemu_try_blockalign() asserts that the
alignment is non zero, while qemu_blockalign() reaches
qemu_try_memalign(), which quietly raises a zero alignment to
sizeof(void *). bs->bl is only filled in once .bdrv_open() returns, so
the alignment has to come from bs->file, which is the node the cluster
is read through anyway and what parallels_open() uses for the header.

Cc: Stefan Hajnoczi <[email protected]>
Cc: Thomas Huth <[email protected]>
Signed-off-by: Denis V. Lunev <[email protected]>
---
 block/parallels-ext.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/block/parallels-ext.c b/block/parallels-ext.c
index 63fe4d5b1e..89fab36039 100644
--- a/block/parallels-ext.c
+++ b/block/parallels-ext.c
@@ -323,10 +323,16 @@ int parallels_read_format_extension(BlockDriverState *bs,
 {
     BDRVParallelsState *s = bs->opaque;
     int ret;
-    uint8_t *ext_cluster = qemu_blockalign(bs, s->cluster_size);
+    uint8_t *ext_cluster;
 
     assert(ext_off > 0);
 
+    ext_cluster = qemu_try_blockalign(bs->file->bs, s->cluster_size);
+    if (!ext_cluster) {
+        error_setg(errp, "Failed to allocate the Format Extension cluster");
+        return -ENOMEM;
+    }
+
     ret = bdrv_pread(bs->file, ext_off, s->cluster_size, ext_cluster, 0);
     if (ret < 0) {
         error_setg_errno(errp, -ret, "Failed to read Format Extension 
cluster");
-- 
2.53.0


Reply via email to