all repos — mgba @ 5afa24c6568e7fc1187cdf7e3ffc0f45e4b0c7d4

mGBA Game Boy Advance Emulator

GBA: Properly handle failed loading of PNG savestates
Jeffrey Pfau jeffrey@endrift.com
Wed, 01 Jul 2015 19:56:10 -0700
commit

5afa24c6568e7fc1187cdf7e3ffc0f45e4b0c7d4

parent

b3ea09e1500072f97ad15c93ba7c90f418742afc

1 files changed, 12 insertions(+), 7 deletions(-)

jump to
M src/gba/serialize.csrc/gba/serialize.c

@@ -229,7 +229,10 @@ }

struct GBASerializedState state; uLongf len = sizeof(state); uncompress((Bytef*) &state, &len, chunk->data, chunk->size); - return GBADeserialize(png_get_user_chunk_ptr(png), &state); + if (!GBADeserialize(png_get_user_chunk_ptr(png), &state)) { + longjmp(png_jmpbuf(png), 1); + } + return 1; } static bool _loadPNGState(struct GBA* gba, struct VFile* vf) {

@@ -243,15 +246,17 @@ }

uint32_t* pixels = malloc(VIDEO_HORIZONTAL_PIXELS * VIDEO_VERTICAL_PIXELS * 4); PNGInstallChunkHandler(png, gba, _loadPNGChunkHandler, "gbAs"); - PNGReadHeader(png, info); - PNGReadPixels(png, info, pixels, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, VIDEO_HORIZONTAL_PIXELS); - PNGReadFooter(png, end); + bool success = PNGReadHeader(png, info); + success = success && PNGReadPixels(png, info, pixels, VIDEO_HORIZONTAL_PIXELS, VIDEO_VERTICAL_PIXELS, VIDEO_HORIZONTAL_PIXELS); + success = success && PNGReadFooter(png, end); PNGReadClose(png, info, end); - gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels); - GBASyncForceFrame(gba->sync); + if (success) { + gba->video.renderer->putPixels(gba->video.renderer, VIDEO_HORIZONTAL_PIXELS, pixels); + GBASyncForceFrame(gba->sync); + } free(pixels); - return true; + return success; } #endif