From 39ff7eacf48c1a95be1a9cb84f1b19c29fafefb2 Mon Sep 17 00:00:00 2001 From: Daniel Gimpelevich Date: Wed, 22 Oct 2025 15:15:35 -0700 Subject: [PATCH] A better fix for ventoy/vtoyboot#48 --- .../grub-2.04/grub-core/ventoy/ventoy_def.h | 7 ++++ .../grub-2.04/grub-core/ventoy/ventoy_vhd.c | 38 ++++++++++++++----- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h index 64a6ba8d4e5..5633319873b 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_def.h @@ -875,6 +875,13 @@ typedef struct VDIPREHEADER grub_uint32_t u32Signature; /** The image version (VDI_IMAGE_VERSION). */ grub_uint32_t u32Version; + grub_uint32_t u32HeaderSize, u32ImageType, u32ImageFlags; + char szDescription[256]; + grub_uint32_t u32BlockmapOffset, u32DataOffset; + grub_uint32_t u32Cylinders, u32Heads, u32Sectors; + grub_uint32_t u32SectorSize, u32Unused1; + grub_uint64_t u64DiskSize; + grub_uint32_t u32BlockSize, u32BlockExtra, u32BlocksInImage, u32BlocksAllocated; } VDIPREHEADER, *PVDIPREHEADER; #pragma pack() diff --git a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c index c5839c2c6c6..6ba4afa1a05 100644 --- a/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c +++ b/GRUB2/MOD_SRC/grub-2.04/grub-core/ventoy/ventoy_vhd.c @@ -539,21 +539,41 @@ grub_err_t ventoy_cmd_get_vtoy_type(grub_extcmd_context_t ctxt, int argc, char * if (vdihdr.u32Signature == VDI_IMAGE_SIGNATURE) { grub_snprintf(type, sizeof(type), "vdi"); - if (grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO, grub_strlen(VDI_IMAGE_FILE_INFO)) == 0) + if (vdihdr.u32ImageType != 2) { - offset = 2 * 1048576; - g_img_trim_head_secnum = offset / 512; - debug("VDI V1\n"); + debug("VDI image must be static, but it is type <%d>\n", vdihdr.u32ImageType); } - else if (grub_strncmp(vdihdr.szFileInfo, VDI_IMAGE_FILE_INFO2, grub_strlen(VDI_IMAGE_FILE_INFO2)) == 0) + else if (vdihdr.u32Version != 0x10001) { - offset = 2 * 1048576; - g_img_trim_head_secnum = offset / 512; - debug("VDI V2\n"); + debug("VDI image must be version 1.1, but it is version <%d.%d>\n", + vdihdr.u32Version >> 16, vdihdr.u32Version & 0xffff); + } + else if (vdihdr.u32SectorSize != 512) + { + debug("VDI image sector size must be 512, but it is <%d>\n", vdihdr.u32SectorSize); + } + else if (vdihdr.u32BlockmapOffset & 0x1ff) + { + debug("VDI image blockmap offset <%d> is not on a sector boundary\n", vdihdr.u32BlockmapOffset); + } + else if (vdihdr.u32DataOffset & 0x1ff) + { + debug("VDI image data offset <%d> is not on a sector boundary\n", vdihdr.u32DataOffset); + } + else if (vdihdr.u32BlockSize != 1048576) + { + debug("VDI image cluster size must be 1048576, but it is <%d>\n", vdihdr.u32BlockSize); + } + else if (vdihdr.u64DiskSize > (grub_uint64_t)vdihdr.u32BlocksInImage << 20) + { + debug("VDI image bitmap has room for only <%lld> bytes, but image is <%lld> bytes\n", + (grub_uint64_t)vdihdr.u32BlocksInImage << 20, vdihdr.u64DiskSize); } else { - debug("invalid file info <%s>\n", vdihdr.szFileInfo); + offset = vdihdr.u32DataOffset; + g_img_trim_head_secnum = offset / 512; + debug("%s\n", vdihdr.szFileInfo); } } else