]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Cancel statefile restore operation if unexpected end of file.
authorToni Wilen <twilen@winuae.net>
Wed, 27 Dec 2017 18:45:49 +0000 (20:45 +0200)
committerToni Wilen <twilen@winuae.net>
Wed, 27 Dec 2017 18:45:49 +0000 (20:45 +0200)
savestate.cpp

index 3e91adb3ed23fda075c19268ac5a8591ebdc0135..f9cf1ec539a5c80b8e5d6ae3e86eddb7c458e98e 100644 (file)
@@ -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;