]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Skip files without filename in archives, lzx empty file and archive inside archive...
authorToni Wilen <twilen@winuae.net>
Sat, 8 Oct 2016 14:03:17 +0000 (17:03 +0300)
committerToni Wilen <twilen@winuae.net>
Sat, 8 Oct 2016 14:03:17 +0000 (17:03 +0300)
archivers/lha/uae_lha.cpp
archivers/lzx/unlzx.cpp
zfile.cpp
zfile_archive.cpp

index 8fea158ab7d6ad77d540641e4eea10f0a13e1627..967b923e9258dabecb0eb47a9c2925d4bda26ac9 100644 (file)
@@ -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;
 }
index b979df70698459cd1b2edd8a105f2c4b66105196..06dfd2a5e16b451be6d4e1ab0e21e0afcc37f1e2 100644 (file)
@@ -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 */
index 1e9f042ad05c1e7e45868f055788477ac52d67ea..0eb4f0eebd31345bed067ee19ca642de51ee9490 100644 (file)
--- 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;
index b83b25f9d6f77314495526fba14d81c4a0f8a154..792e997b098bf4892e87a6720ab2f25cf686dd89 100644 (file)
@@ -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);