CMemoryCardDriver: Avoid crash with corrupt/empty file

This commit is contained in:
Luke Street 2021-04-12 12:22:57 -04:00
parent fb9ea9092a
commit c7f301b485
1 changed files with 3 additions and 0 deletions

View File

@ -39,6 +39,9 @@ ECardResult CMemoryCardDriver::SFileInfo::TryFileRead() {
ECardResult CMemoryCardDriver::SFileInfo::FileRead() { ECardResult CMemoryCardDriver::SFileInfo::FileRead() {
x34_saveData.clear(); x34_saveData.clear();
if (x24_saveFileData.empty()) {
return ECardResult::CRC_MISMATCH;
}
u32 existingCrc = hecl::SBig(*reinterpret_cast<u32*>(x24_saveFileData.data())); u32 existingCrc = hecl::SBig(*reinterpret_cast<u32*>(x24_saveFileData.data()));
u32 newCrc = CCRC32::Calculate(x24_saveFileData.data() + 4, x24_saveFileData.size() - 4); u32 newCrc = CCRC32::Calculate(x24_saveFileData.data() + 4, x24_saveFileData.size() - 4);
if (existingCrc == newCrc) { if (existingCrc == newCrc) {