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

This commit is contained in:
longpanda 2021-03-24 10:07:07 +08:00
parent 33cc1e271a
commit 64748308a3
4 changed files with 41 additions and 1 deletions

View 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;
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))
{