Commit fdf80a4f51 for qemu.org

commit fdf80a4f5162f345405c3a18b223e54decbd1e6a
Author: Peter Maydell <peter.maydell@linaro.org>
Date:   Tue Nov 3 14:35:12 2026 +0000

    block/vmdk: Avoid assertion if image file has no extents

    On a malformed image file which has no extents in it, we will open the file
    but then fall over on an assertion in vmdk_co_get_info():

        $ cat bad.vmdk
        # Disk DescriptorFile
        version=1
        CID=fffffffe
        parentCID=ffffffff
        createType="vmfs"

        $ qemu-img info -f vmdk /tmp/zz9
        qemu-img: ../../block/vmdk.c:3104: int vmdk_co_get_info(BlockDriverState *, BlockDriverInfo *): Assertion `s->num_extents' failed.
        Aborted (core dumped)

    (This was noted in passing in the report of #4571.)

    Cc: qemu-stable@nongnu.org
    Fixes: 7fa60fa3778f1c7336 ("VMDK: open/read/write for monolithicFlat image")
    Reported-by: router0mail <https://gitlab.com/router0mail>
    Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
    Message-ID: <20261103143516.2182626-2-peter.maydell@linaro.org>
    Reviewed-by: Kevin Wolf <kwolf@redhat.com>
    Signed-off-by: Kevin Wolf <kwolf@redhat.com>

diff --git a/block/vmdk.c b/block/vmdk.c
index b6e78a2b5d..86059e1fa0 100644
--- a/block/vmdk.c
+++ b/block/vmdk.c
@@ -1301,6 +1301,12 @@ vmdk_parse_extents(const char *desc, BlockDriverState *bs, QDict *options,
         extent->type = g_strdup(type);
     }

+    if (s->num_extents == 0) {
+        error_setg(errp, "Invalid file: no extent lines present");
+        ret = -EINVAL;
+        goto out;
+    }
+
     ret = 0;
     goto out;