MemoryCardImage: Support importing truncated .gme files
This commit is contained in:
parent
ca0bfc39a2
commit
45dd80b6a6
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue