From 45dd80b6a6c6fd3606aa56ccd961e8d155ed78aa Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Sat, 3 Oct 2020 13:25:39 +1000 Subject: [PATCH] MemoryCardImage: Support importing truncated .gme files --- src/core/memory_card_image.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/core/memory_card_image.cpp b/src/core/memory_card_image.cpp index e329bc077..287532d52 100644 --- a/src/core/memory_card_image.cpp +++ b/src/core/memory_card_image.cpp @@ -421,12 +421,21 @@ static bool ImportCardGME(DataArray* data, const char* filename) if (!file_data.has_value()) return false; - if (file_data->size() < (sizeof(GMEHeader) + DATA_SIZE)) + if (file_data->size() < (sizeof(GMEHeader) + BLOCK_SIZE)) { Log_ErrorPrintf("Failed to import GME memory card from '%s': file is incorrect size.", filename); return false; } + // if it's too small, pad it + const u32 expected_size = sizeof(GMEHeader) + DATA_SIZE; + if (file_data->size() < expected_size) + { + Log_WarningPrintf("GME memory card '%s' is too small (got %zu expected %u), padding with zeroes", filename, + file_data->size(), expected_size); + file_data->resize(expected_size); + } + // we don't actually care about the header, just skip over it std::memcpy(data->data(), file_data->data() + sizeof(GMEHeader), DATA_SIZE); return true;