all repos — mgba @ ee6e53cfc88a09a4f499a038b06856a6acdc6e7b

mGBA Game Boy Advance Emulator

GBA: Check for corrupted savestates when loading
Jeffrey Pfau jeffrey@endrift.com
Mon, 01 Jun 2015 20:52:45 -0700
commit

ee6e53cfc88a09a4f499a038b06856a6acdc6e7b

parent

ab6eac53ee233084380d3bdb7cf3089cabdc758e

2 files changed, 17 insertions(+), 0 deletions(-)

jump to
M CHANGESCHANGES

@@ -34,6 +34,7 @@ - ARM7: Fix Thumb MUL timing

- Qt: Cap the maximum number of multiplayer windows - Qt: Fix maximum year in sensor override - GBA: Cap audio FIFO read size during deserialization + - GBA: Check for corrupted savestates when loading Misc: - Qt: Handle saving input settings better - Debugger: Free watchpoints in addition to breakpoints
M src/gba/serialize.csrc/gba/serialize.c

@@ -74,6 +74,22 @@ }

if (state->romCrc32 != gba->romCrc32) { GBALog(gba, GBA_LOG_WARN, "Savestate is for a different version of the game"); } + if (state->cpu.cycles < 0) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: CPU cycles are negative"); + return; + } + if (state->video.nextHblank - state->video.eventDiff < 0) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: nextHblank is negative"); + return; + } + if (state->video.lastHblank - state->video.eventDiff < -VIDEO_HBLANK_LENGTH) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: lastHblank is negative"); + return; + } + if (state->timers[0].overflowInterval < 0 || state->timers[1].overflowInterval < 0 || state->timers[2].overflowInterval < 0 || state->timers[3].overflowInterval < 0) { + GBALog(gba, GBA_LOG_WARN, "Savestate is corrupted: overflowInterval is negative"); + return; + } memcpy(gba->cpu->gprs, state->cpu.gprs, sizeof(gba->cpu->gprs)); gba->cpu->cpsr = state->cpu.cpsr; gba->cpu->spsr = state->cpu.spsr;