From: Toni Wilen Date: Sat, 8 Oct 2016 14:03:17 +0000 (+0300) Subject: Skip files without filename in archives, lzx empty file and archive inside archive... X-Git-Tag: 3400~59 X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=c43fed88daeacc0ef1062f6483952ac5f9edbbdc;p=francis%2Fwinuae.git Skip files without filename in archives, lzx empty file and archive inside archive fix. --- diff --git a/archivers/lha/uae_lha.cpp b/archivers/lha/uae_lha.cpp index 8fea158a..967b923e 100644 --- a/archivers/lha/uae_lha.cpp +++ b/archivers/lha/uae_lha.cpp @@ -9,7 +9,7 @@ #include "zarchive.h" -static char *methods[] = +static const char *methods[] = { LZHUFF0_METHOD, LZHUFF1_METHOD, LZHUFF2_METHOD, LZHUFF3_METHOD, LZHUFF4_METHOD, LZHUFF5_METHOD, LZHUFF6_METHOD, LZHUFF7_METHOD, @@ -28,45 +28,46 @@ struct zvolume *archive_directory_lha (struct zfile *zf) _tzset(); zv = zvolume_alloc (zf, ArchiveFormatLHA, NULL, NULL); while (get_header(zf, &hdr)) { - struct znode *zn; - int method; + struct znode *zn; + int method; - for (i = 0; methods[i]; i++) { - if (!strcmp (methods[i], hdr.method)) - method = i; - } - memset (&zai, 0, sizeof zai); - zai.name = au (hdr.name); - zai.size = hdr.original_size; - zai.flags = hdr.attribute; - if (hdr.extend_type != 0) { - zai.tv.tv_sec = hdr.unix_last_modified_stamp -= _timezone; - } else { - struct tm t; - uae_u32 v = hdr.last_modified_stamp; - - t.tm_sec = (v & 0x1f) * 2; - t.tm_min = (v >> 5) & 0x3f; - t.tm_hour = (v >> 11) & 0x1f; - t.tm_mday = (v >> 16) & 0x1f; - t.tm_mon = ((v >> 21) & 0xf) - 1; - t.tm_year = ((v >> 25) & 0x7f) + 80; - zai.tv.tv_sec = mktime (&t) - _timezone; - } - if (hdr.name[strlen(hdr.name) + 1] != 0) - zai.comment = au (&hdr.name[strlen(hdr.name) + 1]); - if (method == LZHDIRS_METHOD_NUM) { - zvolume_adddir_abs (zv, &zai); - } else { - zn = zvolume_addfile_abs (zv, &zai); - zn->offset = zfile_ftell(zf); - zn->packedsize = hdr.packed_size; - zn->method = method; - } - xfree (zai.name); - xfree (zai.comment); - zfile_fseek (zf, hdr.packed_size, SEEK_CUR); + for (i = 0; methods[i]; i++) { + if (!strcmp (methods[i], hdr.method)) + method = i; + } + memset (&zai, 0, sizeof zai); + zai.name = au (hdr.name); + zai.size = hdr.original_size; + zai.flags = hdr.attribute; + if (hdr.extend_type != 0) { + zai.tv.tv_sec = hdr.unix_last_modified_stamp -= _timezone; + } else { + struct tm t; + uae_u32 v = hdr.last_modified_stamp; + t.tm_sec = (v & 0x1f) * 2; + t.tm_min = (v >> 5) & 0x3f; + t.tm_hour = (v >> 11) & 0x1f; + t.tm_mday = (v >> 16) & 0x1f; + t.tm_mon = ((v >> 21) & 0xf) - 1; + t.tm_year = ((v >> 25) & 0x7f) + 80; + zai.tv.tv_sec = mktime (&t) - _timezone; + } + if (hdr.name[strlen(hdr.name) + 1] != 0) + zai.comment = au (&hdr.name[strlen(hdr.name) + 1]); + if (method == LZHDIRS_METHOD_NUM) { + zvolume_adddir_abs (zv, &zai); + } else { + zn = zvolume_addfile_abs (zv, &zai); + if (zn) { + zn->offset = zfile_ftell(zf); + zn->packedsize = hdr.packed_size; + zn->method = method; + } + } + xfree (zai.name); + xfree (zai.comment); + zfile_fseek (zf, hdr.packed_size, SEEK_CUR); } return zv; } diff --git a/archivers/lzx/unlzx.cpp b/archivers/lzx/unlzx.cpp index b979df70..06dfd2a5 100644 --- a/archivers/lzx/unlzx.cpp +++ b/archivers/lzx/unlzx.cpp @@ -712,12 +712,17 @@ struct zfile *archive_access_lzx (struct znode *zn) } /* pre-cache all files we just decompressed */ for (;;) { - if (znfirst->size && !znfirst->f) { + if (!znfirst->f) { dstf = zfile_fopen_empty (zf, znfirst->name, znfirst->size); - zfile_fwrite(dbuf + znfirst->offset2, znfirst->size, 1, dstf); + if (znfirst->size) { + zfile_fwrite(dbuf + znfirst->offset2, znfirst->size, 1, dstf); + } znfirst->f = dstf; if (znfirst == zn) - newzf = zfile_dup (dstf); + newzf = zfile_dup (dstf); + } else { + if (znfirst == zn) + newzf = zfile_dup(znfirst->f); } if (znfirst == znlast) break; @@ -828,8 +833,11 @@ struct zvolume *archive_directory_lzx (struct zfile *in_file) tm.tm_mday = day; zai.tv.tv_sec = mktime(&tm); zai.size = unpack_size; + zn = zvolume_addfile_abs(zv, &zai); - zn->offset2 = merge_size; + if (zn) { + zn->offset2 = merge_size; + } xfree (zai.name); xfree (zai.comment); @@ -841,8 +849,10 @@ struct zvolume *archive_directory_lzx (struct zfile *in_file) if(pack_size) /* seek past the packed data */ { merge_size = 0; - zn->offset = zfile_ftell(in_file); - zn->packedsize = pack_size; + if (zn) { + zn->offset = zfile_ftell(in_file); + zn->packedsize = pack_size; + } if(!zfile_fseek(in_file, pack_size, SEEK_CUR)) { abort = 0; /* continue */ diff --git a/zfile.cpp b/zfile.cpp index 1e9f042a..0eb4f0ee 100644 --- a/zfile.cpp +++ b/zfile.cpp @@ -2960,6 +2960,14 @@ static void addvolumesize (struct zvolume *zv, uae_s64 size) } } +static bool valid_zi(struct zarchive_info *zai) +{ + if (_tcslen(zai->name) == 0) { + return false; + } + return true; +} + struct znode *znode_adddir (struct znode *parent, const TCHAR *name, struct zarchive_info *zai) { struct znode *zn; @@ -2998,6 +3006,10 @@ struct znode *zvolume_adddir_abs (struct zvolume *zv, struct zarchive_info *zai) if (last == '/' || last == '\\') path[_tcslen (path) - 1] = 0; } + if (!valid_zi(zai)) { + xfree(path); + return NULL; + } zn2 = &zv->root; p = p2 = path; for (i = 0; path[i]; i++) { @@ -3015,7 +3027,7 @@ struct znode *zvolume_addfile_abs (struct zvolume *zv, struct zarchive_info *zai { struct znode *zn = NULL, *zn2; int i; - TCHAR *path = my_strdup (zai->name); + TCHAR *path = my_strdup(zai->name); TCHAR *p, *p2; zn2 = &zv->root; @@ -3028,7 +3040,7 @@ struct znode *zvolume_addfile_abs (struct zvolume *zv, struct zarchive_info *zai p = p2 = &path[i + 1]; } } - if (p2) { + if (p2 && _tcslen(p2) > 0) { zn = znode_alloc_child (zn2, p2); zn->size = zai->size; zn->type = ZNODE_FILE; diff --git a/zfile_archive.cpp b/zfile_archive.cpp index b83b25f9..792e997b 100644 --- a/zfile_archive.cpp +++ b/zfile_archive.cpp @@ -613,7 +613,8 @@ struct zvolume *archive_directory_7z (struct zfile *z) } if (!f->IsDir) { struct znode *zn = zvolume_addfile_abs (zv, &zai); - zn->offset = i; + if (zn) + zn->offset = i; } } zv->method = ArchiveFormat7Zip; @@ -764,7 +765,8 @@ struct zvolume *archive_directory_rar (struct zfile *z) zai.flags = -1; zai.tv.tv_sec = fromdostime (rc->HeaderData.FileTime); zn = zvolume_addfile_abs (zv, &zai); - zn->offset = cnt++; + if (zn) + zn->offset = cnt++; pRARProcessFile (rc->hArcData, RAR_SKIP, NULL, NULL); } pRARCloseArchive (rc->hArcData); @@ -960,9 +962,11 @@ struct zvolume *archive_directory_arcacc (struct zfile *z, unsigned int id) zai.flags = -1; zai.size = (unsigned int)fi.UncompressedFileSize; zn = zvolume_addfile_abs (zv, &zai); - xfree (name); - zn->offset = f; - zn->method = id; + if (zn) { + zn->offset = f; + zn->method = id; + } + xfree(name); if (id == ArchiveFormat7Zip) { if (fi.CompressedFileSize) @@ -1078,7 +1082,8 @@ struct zvolume *archive_directory_plain (struct zfile *z) zai.size = zfile_ftell (zf2); zfile_fseek (zf2, 0, SEEK_SET); zn = zvolume_addfile_abs (zv, &zai); - zn->f = zf2; + if (zn) + zn->f = zf2; // if (zn) // zn->offset = index + 1; // zfile_fclose (zf2); @@ -1249,11 +1254,14 @@ static void recurseadf (struct znode *zn, int root, TCHAR *name) amiga_to_timeval (&zai.tv, gl (adf, bs - 23 * 4), gl (adf, bs - 22 * 4),gl (adf, bs - 21 * 4), 50); if (secondary == -3) { struct znode *znnew = zvolume_addfile_abs (zv, &zai); - znnew->offset = block; + if (znnew) + znnew->offset = block; } else { struct znode *znnew = zvolume_adddir_abs (zv, &zai); - znnew->offset = block; - recurseadf (znnew, block, name2); + if (znnew) { + znnew->offset = block; + recurseadf (znnew, block, name2); + } if (!adf_read_block (adf, block)) return; } @@ -1335,8 +1343,10 @@ static void recursesfs (struct znode *zn, int root, TCHAR *name, int sfs2) zai.size = glx (p + 16); } znnew = zvolume_addfile_abs (zv, &zai); - znnew->offset = block; - znnew->offset2 = p - adf->block; + if (znnew) { + znnew->offset = block; + znnew->offset2 = p - adf->block; + } } xfree (zai.comment); xfree (fname); @@ -1736,8 +1746,10 @@ struct zvolume *archive_directory_rdb (struct zfile *z) zai.size = size; zai.flags = -1; zn = zvolume_addfile_abs (zv, &zai); - zn->offset = partblock; - zn->offset2 = blocksize; // abuse of offset2.. + if (zn) { + zn->offset = partblock; + zn->offset2 = blocksize; // abuse of offset2.. + } } zfile_fseek (z, 0, SEEK_SET); @@ -1985,7 +1997,9 @@ static void fatdirectory (struct zfile *z, struct zvolume *zv, const TCHAR *name } else { zai.size = size; znnew = zvolume_addfile_abs (zv, &zai); - znnew->offset = startcluster; + if (znnew) { + znnew->offset = startcluster; + } } xfree (fname);