Add a workaround for buggy bootloader's out-of-range access

pull/809/head
longpanda 3 years ago
parent 33cc1e271a
commit 64748308a3

@ -438,6 +438,8 @@ EFI_STATUS EFIAPI ventoy_block_io_read
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;
@ -461,6 +463,22 @@ EFI_STATUS EFIAPI ventoy_block_io_read
{
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)
{

@ -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
elif [ -f (loop)/porteus/initrd.xz ]; then
vt_linux_specify_initrd_file /porteus/initrd.xz
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
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"

Binary file not shown.

@ -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;
uint64_t VirtSec;
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;
}
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))
{

Loading…
Cancel
Save