diff options
author | Couriersud <couriersud@users.noreply.github.com> | 2009-03-04 21:30:52 +0000 |
---|---|---|
committer | Couriersud <couriersud@users.noreply.github.com> | 2009-03-04 21:30:52 +0000 |
commit | 8d92bff0b76904cc108c89dd0e8a9885dffb0592 (patch) | |
tree | af8e5e06c97d8d0408311828a4786c5415846819 /src | |
parent | caf233e1fc1fbbb7a388e361584a908d19fbdf6e (diff) |
02180: Corrupt archives are read without problems
* corrupt files in archives now generate an error
* archive files ending in "/" will not be tested for crc - skip path entries
* add new flag FILE_OPEN_NO_PRELOAD to skip decompressing on open
This is used in audit.c, which only tests whether files exist
* added error checking to all calls to load_file_zipped
Diffstat (limited to 'src')
-rw-r--r-- | src/emu/audit.c | 12 | ||||
-rw-r--r-- | src/emu/fileio.c | 65 | ||||
-rw-r--r-- | src/osd/osdcore.h | 1 |
3 files changed, 61 insertions, 17 deletions
diff --git a/src/emu/audit.c b/src/emu/audit.c index 6b7e8c4d7a1..856857013c9 100644 --- a/src/emu/audit.c +++ b/src/emu/audit.c @@ -188,13 +188,13 @@ int audit_samples(core_options *options, const game_driver *gamedrv, audit_recor /* attempt to access the file from the game driver name */ fname = astring_assemble_3(astring_alloc(), gamedrv->name, PATH_SEPARATOR, intf->samplenames[sampnum]); - filerr = mame_fopen_options(options, SEARCHPATH_SAMPLE, astring_c(fname), OPEN_FLAG_READ, &file); + filerr = mame_fopen_options(options, SEARCHPATH_SAMPLE, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); /* attempt to access the file from the shared driver name */ if (filerr != FILERR_NONE && sharedname != NULL) { astring_assemble_3(fname, sharedname, PATH_SEPARATOR, intf->samplenames[sampnum]); - filerr = mame_fopen_options(options, SEARCHPATH_SAMPLE, astring_c(fname), OPEN_FLAG_READ, &file); + filerr = mame_fopen_options(options, SEARCHPATH_SAMPLE, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); } astring_free(fname); @@ -356,9 +356,9 @@ static int audit_one_rom(core_options *options, const rom_entry *rom, const char /* open the file if we can */ fname = astring_assemble_3(astring_alloc(), drv->name, PATH_SEPARATOR, ROM_GETNAME(rom)); if (has_crc) - filerr = mame_fopen_crc_options(options, SEARCHPATH_ROM, astring_c(fname), crc, OPEN_FLAG_READ, &file); + filerr = mame_fopen_crc_options(options, SEARCHPATH_ROM, astring_c(fname), crc, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); else - filerr = mame_fopen_options(options, SEARCHPATH_ROM, astring_c(fname), OPEN_FLAG_READ, &file); + filerr = mame_fopen_options(options, SEARCHPATH_ROM, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); astring_free(fname); /* if we got it, extract the hash and length */ @@ -381,9 +381,9 @@ static int audit_one_rom(core_options *options, const rom_entry *rom, const char /* open the file if we can */ fname = astring_assemble_3(astring_alloc(), regiontag, PATH_SEPARATOR, ROM_GETNAME(rom)); if (has_crc) - filerr = mame_fopen_crc_options(options, SEARCHPATH_ROM, astring_c(fname), crc, OPEN_FLAG_READ, &file); + filerr = mame_fopen_crc_options(options, SEARCHPATH_ROM, astring_c(fname), crc, OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); else - filerr = mame_fopen_options(options, SEARCHPATH_ROM, astring_c(fname), OPEN_FLAG_READ, &file); + filerr = mame_fopen_options(options, SEARCHPATH_ROM, astring_c(fname), OPEN_FLAG_READ | OPEN_FLAG_NO_PRELOAD, &file); astring_free(fname); /* if we got it, extract the hash and length */ diff --git a/src/emu/fileio.c b/src/emu/fileio.c index eeadf45329c..e9e073c8ca3 100644 --- a/src/emu/fileio.c +++ b/src/emu/fileio.c @@ -92,6 +92,7 @@ static int path_iterator_get_next(path_iterator *iterator, astring *buffer); /* misc helpers */ static file_error load_zipped_file(mame_file *file); static int zip_filename_match(const zip_file_header *header, const astring *afilename); +static int zip_header_is_path(const zip_file_header *header); @@ -324,7 +325,7 @@ static file_error fopen_attempt_zipped(astring *fullname, UINT32 crc, UINT32 ope /* if that failed, look for a file with the right crc, but the wrong filename */ if (header == NULL && (openflags & OPEN_FLAG_HAS_CRC)) for (header = zip_file_first_file(zip); header != NULL; header = zip_file_next_file(zip)) - if (header->crc == crc) + if (header->crc == crc && (!zip_header_is_path(header))) break; /* if that failed, look for a file with the right name; reporting a bad checksum */ @@ -351,7 +352,10 @@ static file_error fopen_attempt_zipped(astring *fullname, UINT32 crc, UINT32 ope hash_data_insert_binary_checksum(file->hash, HASH_CRC, crcs); astring_free(filename); - return FILERR_NONE; + if (openflags & OPEN_FLAG_NO_PRELOAD) + return FILERR_NONE; + else + return load_zipped_file(file); } /* close up the ZIP file and try the next level */ @@ -409,7 +413,10 @@ int mame_fseek(mame_file *file, INT64 offset, int whence) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return 1; + } /* seek if we can */ if (file->file != NULL) @@ -427,7 +434,10 @@ UINT64 mame_ftell(mame_file *file) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return 0; + } /* tell if we can */ if (file->file != NULL) @@ -446,7 +456,10 @@ int mame_feof(mame_file *file) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return 0; + } /* return EOF if we can */ if (file->file != NULL) @@ -487,7 +500,10 @@ UINT32 mame_fread(mame_file *file, void *buffer, UINT32 length) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return 0; + } /* read the data if we can */ if (file->file != NULL) @@ -505,7 +521,10 @@ int mame_fgetc(mame_file *file) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return EOF; + } /* read the data if we can */ if (file->file != NULL) @@ -524,7 +543,10 @@ int mame_ungetc(int c, mame_file *file) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return 1; + } /* read the data if we can */ if (file->file != NULL) @@ -542,7 +564,10 @@ char *mame_fgets(char *s, int n, mame_file *file) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return NULL; + } /* read the data if we can */ if (file->file != NULL) @@ -706,7 +731,10 @@ core_file *mame_core_file(mame_file *file) { /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return NULL; + } /* return the core file */ return file->file; @@ -743,7 +771,10 @@ const char *mame_fhash(mame_file *file, UINT32 functions) /* load the ZIP file now if we haven't yet */ if (file->zipfile != NULL) - load_zipped_file(file); + { + if (load_zipped_file(file) != FILERR_NONE) + return file->hash; + } if (file->file == NULL) return file->hash; @@ -863,3 +894,15 @@ static int zip_filename_match(const zip_file_header *header, const astring *file return (zipfile >= header->filename && astring_icmpc(filename, zipfile) == 0 && (zipfile == header->filename || zipfile[-1] == '/')); } + +/*------------------------------------------------- + zip_header_is_path - check whether filename + in header is a path + -------------------------------------------------*/ + +static int zip_header_is_path(const zip_file_header *header) +{ + const char *zipfile = header->filename + header->filename_length - 1; + + return (zipfile >= header->filename && zipfile[0] == '/'); +} diff --git a/src/osd/osdcore.h b/src/osd/osdcore.h index bf349259a6e..f28fb0f932c 100644 --- a/src/osd/osdcore.h +++ b/src/osd/osdcore.h @@ -38,6 +38,7 @@ #define OPEN_FLAG_WRITE 0x0002 /* open for write */ #define OPEN_FLAG_CREATE 0x0004 /* create & truncate file */ #define OPEN_FLAG_CREATE_PATHS 0x0008 /* create paths as necessary */ +#define OPEN_FLAG_NO_PRELOAD 0x0010 /* do not decompress on open */ /* error codes returned by routines below */ enum _file_error |