From 3951fbe8286c4b7a4ce9c67d9a48d0ff692e1123 Mon Sep 17 00:00:00 2001 From: LuigiBlood Date: Wed, 14 Aug 2019 16:18:31 +0200 Subject: [PATCH] [Disk] Perform Filesize check for D64 files, remove useless check --- Source/Project64-core/N64System/N64DiskClass.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Source/Project64-core/N64System/N64DiskClass.cpp b/Source/Project64-core/N64System/N64DiskClass.cpp index 6c80fc026..11a98c764 100644 --- a/Source/Project64-core/N64System/N64DiskClass.cpp +++ b/Source/Project64-core/N64System/N64DiskClass.cpp @@ -382,7 +382,8 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc) uint16_t ROM_LBA_END = (Test[0xE0] << 8) | Test[0xE1]; uint16_t RAM_LBA_START = (Test[0xE2] << 8) | Test[0xE3]; - if ((ROM_LBA_END + SYSTEM_LBAS) >= RAM_START_LBA[m_DiskType] || ROM_LBA_END == 0 || ((RAM_LBA_START + SYSTEM_LBAS) != RAM_START_LBA[m_DiskType] && RAM_LBA_START != 0xFFFF)) + if ((ROM_LBA_END + SYSTEM_LBAS) >= RAM_START_LBA[m_DiskType] || + ((RAM_LBA_START + SYSTEM_LBAS) != RAM_START_LBA[m_DiskType] && RAM_LBA_START != 0xFFFF)) { m_DiskFile.Close(); SetError(MSG_FAIL_IMAGE); @@ -393,6 +394,14 @@ bool CN64Disk::AllocateAndLoadDiskImage(const char * FileLoc) uint32_t ROM_SIZE = LBAToByte(SYSTEM_LBAS, ROM_LBA_END + 1); uint32_t RAM_SIZE = RAM_SIZES[m_DiskType]; + if ((0x200 + ROM_SIZE) > DiskFileSize) + { + m_DiskFile.Close(); + SetError(MSG_FAIL_IMAGE); + WriteTrace(TraceN64System, TraceError, "Malformed D64 disk image, expected minimum filesize of %08X, filesize: %08X", (0x200 + ROM_SIZE), DiskFileSize); + return false; + } + //Allocate File with Max RAM Area size WriteTrace(TraceN64System, TraceError, "Allocate D64 ROM %08X + RAM %08X", ROM_SIZE, RAM_SIZE); if (!AllocateDiskImage(0x200 + ROM_SIZE + RAM_SIZE))