From: Toni Wilen Date: Wed, 27 Dec 2017 18:45:49 +0000 (+0200) Subject: Cancel statefile restore operation if unexpected end of file. X-Git-Tag: 3600~19 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=b87af4478cc1641075235cd162cc39622a7a2949;p=francis%2Fwinuae.git Cancel statefile restore operation if unexpected end of file. --- diff --git a/savestate.cpp b/savestate.cpp index 3e91adb3..f9cf1ec5 100644 --- a/savestate.cpp +++ b/savestate.cpp @@ -374,12 +374,18 @@ static uae_u8 *restore_chunk (struct zfile *f, TCHAR *name, unsigned int *len, u int len2; *totallen = 0; + *filepos = 0; + *name = 0; /* chunk name */ - zfile_fread (tmp, 1, 4, f); + if (zfile_fread(tmp, 1, 4, f) != 4) + return NULL; tmp[4] = 0; au_copy (name, 5, (char*)tmp); /* chunk size */ - zfile_fread (tmp, 1, 4, f); + if (zfile_fread(tmp, 1, 4, f) != 4) { + *name = 0; + return NULL; + } src = tmp; len2 = restore_u32 () - 4 - 4 - 4; if (len2 < 0) @@ -391,7 +397,10 @@ static uae_u8 *restore_chunk (struct zfile *f, TCHAR *name, unsigned int *len, u } /* chunk flags */ - zfile_fread (tmp, 1, 4, f); + if (zfile_fread(tmp, 1, 4, f) != 4) { + *name = 0; + return NULL; + } src = tmp; flags = restore_u32 (); *totallen = *len; @@ -726,6 +735,8 @@ void restore_state (const TCHAR *filename) write_log (_T("Chunk '%s' total size %d bytes but read %ld bytes!\n"), name, totallen, end - chunk); xfree (chunk); + if (name[0] == 0) + break; } target_addtorecent (filename, 0); return;