From ddaff077b200a056e939bb3091c93f48128bc379 Mon Sep 17 00:00:00 2001 From: LuigiBlood Date: Wed, 14 Aug 2019 16:32:13 +0200 Subject: [PATCH] [Disk] Add more failsafe in case of invalid offsets --- .../Project64-core/N64System/N64DiskClass.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/Source/Project64-core/N64System/N64DiskClass.cpp b/Source/Project64-core/N64System/N64DiskClass.cpp index 11a98c764..1fe2342f3 100644 --- a/Source/Project64-core/N64System/N64DiskClass.cpp +++ b/Source/Project64-core/N64System/N64DiskClass.cpp @@ -668,6 +668,11 @@ uint32_t CN64Disk::GetDiskAddressBlock(uint16_t head, uint16_t track, uint16_t b offset = 0xFFFFFFFF; } } + + if (offset >= m_DiskFileSize) + { + offset = 0xFFFFFFFF; + } if (sector == 0) { WriteTrace(TraceN64System, TraceDebug, "Head %d Track %d Block %d - LBA %d - Address %08X", head, track, block, PhysToLBA(head, track, block), offset); @@ -797,8 +802,16 @@ void CN64Disk::InitSysDataD64() GetDiskAddressSys()[5 ^ 3] |= 0x10; //Expand RAM Area for file format consistency - *(uint16_t*)&GetDiskAddressSys()[0xE2 ^ 2] = RAM_START_LBA[m_DiskType] - SYSTEM_LBAS; - *(uint16_t*)&GetDiskAddressSys()[0xE4 ^ 2] = MAX_LBA - SYSTEM_LBAS; + if (m_DiskType < 6) + { + *(uint16_t*)&GetDiskAddressSys()[0xE2 ^ 2] = RAM_START_LBA[m_DiskType] - SYSTEM_LBAS; + *(uint16_t*)&GetDiskAddressSys()[0xE4 ^ 2] = MAX_LBA - SYSTEM_LBAS; + } + else + { + *(uint16_t*)&GetDiskAddressSys()[0xE2 ^ 2] = 0xFFFF; + *(uint16_t*)&GetDiskAddressSys()[0xE4 ^ 2] = 0xFFFF; + } } void CN64Disk::DeinitSysDataD64()