Merge pull request #1059 from 269261/rom-size-checks

Add missing ROM file size checks
This commit is contained in:
Richard Goedeken 2024-01-24 22:06:32 -08:00 committed by GitHub
commit 1656545339
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -180,7 +180,8 @@ EXPORT m64p_error CALL CoreDoCommand(m64p_command Command, int ParamInt, void *P
case M64CMD_ROM_OPEN:
if (g_EmulatorRunning || l_DiskOpen || l_ROMOpen)
return M64ERR_INVALID_STATE;
if (ParamPtr == NULL || ParamInt < 4096)
// ROM buffer size must be divisible by 4 to avoid out-of-bounds read in swap_copy_rom (v64/n64 formats)
if (ParamPtr == NULL || ParamInt < 4096 || ParamInt > CART_ROM_MAX_SIZE || ParamInt % 4 != 0)
return M64ERR_INPUT_ASSERT;
rval = open_rom((const unsigned char *) ParamPtr, ParamInt);
if (rval == M64ERR_SUCCESS)