]> glassweightruler.freedombox.rocks Git - Ventoy.git/commitdiff
Add a workaround for buggy bootloader's out-of-range access
authorlongpanda <admin@ventoy.net>
Wed, 24 Mar 2021 02:07:07 +0000 (10:07 +0800)
committerlongpanda <admin@ventoy.net>
Wed, 24 Mar 2021 02:07:07 +0000 (10:07 +0800)
EDK2/edk2_mod/edk2-edk2-stable201911/MdeModulePkg/Application/Ventoy/VentoyProtocol.c
INSTALL/grub/grub.cfg
INSTALL/ventoy/ipxe.krn
IPXE/ipxe_mod_code/ipxe-3fe683e/src/arch/x86/core/ventoy_vdisk.c

index c8b798438247eac3c1800d6bd36079b0d6c3ef76..a6e168e05a1e0d873adb8c84226cf67089acf03b 100644 (file)
@@ -438,6 +438,8 @@ EFI_STATUS EFIAPI ventoy_block_io_read
     UINT32 j = 0;
     UINT32 lbacount = 0;
     UINT32 secNum = 0;
     UINT32 j = 0;
     UINT32 lbacount = 0;
     UINT32 secNum = 0;
+    UINT32 TmpNum = 0;
+    UINT64 VirtSec = 0;
     UINT64 offset = 0;
     EFI_LBA curlba = 0;
     EFI_LBA lastlba = 0;
     UINT64 offset = 0;
     EFI_LBA curlba = 0;
     EFI_LBA lastlba = 0;
@@ -461,6 +463,22 @@ EFI_STATUS EFIAPI ventoy_block_io_read
     {
         return ventoy_read_iso_sector(Lba, secNum, Buffer);
     }
     {
         return ventoy_read_iso_sector(Lba, secNum, Buffer);
     }
+    else if (offset < g_chain->real_img_size_in_bytes)
+    {
+        TmpNum = (g_chain->real_img_size_in_bytes - offset) / 2048;
+        ventoy_read_iso_sector(Lba, TmpNum, Buffer);
+
+        Lba += TmpNum;
+        secNum -= TmpNum;
+        Buffer = (UINT8 *)Buffer + (g_chain->real_img_size_in_bytes - offset);
+        offset = Lba * 2048;
+    }
+
+    VirtSec = g_chain->virt_img_size_in_bytes / 2048;    
+    if (Lba + secNum > VirtSec)
+    {
+        secNum = VirtSec - Lba;
+    }
 
     if (secNum > g_sector_flag_num)
     {
 
     if (secNum > g_sector_flag_num)
     {
index 3d45f5ac5186cffd31585f369610816f54c3b741..673beb9bfb111434a01f888cc01d82afa2ac6e13 100644 (file)
@@ -311,6 +311,8 @@ function distro_specify_initrd_file_phase2 {
         vt_linux_specify_initrd_file /antiX/initrd.gz
     elif [ -f (loop)/360Disk/initrd.gz ]; then
         vt_linux_specify_initrd_file /360Disk/initrd.gz
         vt_linux_specify_initrd_file /antiX/initrd.gz
     elif [ -f (loop)/360Disk/initrd.gz ]; then
         vt_linux_specify_initrd_file /360Disk/initrd.gz
+    elif [ -f (loop)/porteus/initrd.xz ]; then
+        vt_linux_specify_initrd_file /porteus/initrd.xz
     
     fi
 }
     
     fi
 }
@@ -1030,7 +1032,7 @@ function iso_common_menuentry {
     vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id vt_volume_space
     if [ $vt_volume_space -ne $vt_chosen_size ]; then        
         vt_mod $vt_chosen_size 2048 vt_chosen_size_mod
     vt_parse_iso_volume "${vtoy_iso_part}${vt_chosen_path}" vt_system_id vt_volume_id vt_volume_space
     if [ $vt_volume_space -ne $vt_chosen_size ]; then        
         vt_mod $vt_chosen_size 2048 vt_chosen_size_mod
-        if [ $vt_volume_space -gt $vt_chosen_size -o $vt_chosen_size_mod -ne 0 ]; then
+        if [ $vt_chosen_size_mod -ne 0 ]; then
             echo -e "\n $vt_volume_space $vt_chosen_size $vt_chosen_size_mod\n"
             echo -e "\n The size of the iso file \"$vt_chosen_size\" is invalid. File corrupted ?\n"
             echo -e " 此ISO文件的大小 \"$vt_chosen_size\" 有问题,请确认文件是否损坏。\n"
             echo -e "\n $vt_volume_space $vt_chosen_size $vt_chosen_size_mod\n"
             echo -e "\n The size of the iso file \"$vt_chosen_size\" is invalid. File corrupted ?\n"
             echo -e " 此ISO文件的大小 \"$vt_chosen_size\" 有问题,请确认文件是否损坏。\n"
index deafc667adde2dccd939a6ecefc7c90f2dfdd976..229bdddc83a4ad25e402cb5cd30b1a5b4fca5218 100644 (file)
Binary files a/INSTALL/ventoy/ipxe.krn and b/INSTALL/ventoy/ipxe.krn differ
index 0224b8aba0ddf785d25f6c8ecca71a12512e40e2..58cc9750f60dab0477352dea7e2d28d24d050893 100644 (file)
@@ -386,6 +386,7 @@ int ventoy_vdisk_read(struct san_device *sandev, uint64_t lba, unsigned int coun
     uint32_t lbacount = 0;
     unsigned long lastbuffer;
     uint64_t readend;
     uint32_t lbacount = 0;
     unsigned long lastbuffer;
     uint64_t readend;
+    uint64_t VirtSec;
     ventoy_virt_chunk *node;
     ventoy_sector_flag *cur_flag;
     ventoy_sector_flag *sector_flag = g_sector_flag;
     ventoy_virt_chunk *node;
     ventoy_sector_flag *cur_flag;
     ventoy_sector_flag *sector_flag = g_sector_flag;
@@ -419,6 +420,25 @@ int ventoy_vdisk_read(struct san_device *sandev, uint64_t lba, unsigned int coun
         ix86->regs.dl = sandev->drive;
         return 0;
     }
         ix86->regs.dl = sandev->drive;
         return 0;
     }
+    else if ((lba * 2048) < g_chain->real_img_size_in_bytes)
+    {
+        /* fix for grub4dos Inconsistent data read from error */
+        memset((void *)(buffer + (count - 1) * 2048), 0, 2048);
+        
+        count = (g_chain->real_img_size_in_bytes / 2048) - lba;
+        ventoy_vdisk_read_real(lba, count, buffer);
+        ix86->regs.dl = sandev->drive;
+
+        lba += count;
+        buffer += count * 2048;
+        count = (readend - g_chain->real_img_size_in_bytes) / 2048;
+    }
+
+    VirtSec = g_chain->virt_img_size_in_bytes / 2048;    
+    if (lba + count > VirtSec)
+    {
+        count = VirtSec - lba;
+    }
 
     if (count > sizeof(g_sector_flag))
     {
 
     if (count > sizeof(g_sector_flag))
     {