]> granicus.if.org Git - php/commitdiff
Fixed bug #64452 Zip PHPTs crash intermittently
authorAnatol Belski <ab@php.net>
Wed, 20 Mar 2013 08:10:10 +0000 (09:10 +0100)
committerAnatol Belski <ab@php.net>
Wed, 20 Mar 2013 08:10:10 +0000 (09:10 +0100)
NEWS
ext/zip/lib/zip_close.c
ext/zip/lib/zip_dirent.c

diff --git a/NEWS b/NEWS
index facb9ad154947fc095e75569900bc3f0297e5d98..d62e1a189dfa06ae7ce309ab0ab015a31e1aec60 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,9 @@ PHP                                                                        NEWS
 - DateTime
   . Fixed bug #62852 (Unserialize Invalid Date causes crash). (Anatol)
 
+- Zip:
+  . Bug #64452 (Zip crash intermittently). (Anatol)
+
 
 14 Mar 2013, PHP 5.3.23
 
index 362f92d749cc91e0510210c5b91b213ac863d613..e66c56697b14d2ad32e97682d8d3dee1068e42c2 100644 (file)
@@ -88,6 +88,9 @@ zip_close(struct zip *za)
     if (za == NULL)
        return -1;
 
+    if (za->zp == NULL)
+        return -1;
+
     if (!_zip_changed(za, &survivors)) {
        _zip_free(za);
        return 0;
@@ -164,9 +167,10 @@ zip_close(struct zip *za)
     for (j=0; j<survivors; j++) {
        i = filelist[j].idx;
 
+       _zip_dirent_init(&de);
+
        /* create new local directory entry */
        if (ZIP_ENTRY_DATA_CHANGED(za->entry+i) || new_torrentzip) {
-           _zip_dirent_init(&de);
 
            if (zip_get_archive_flag(za, ZIP_AFL_TORRENT, 0))
                _zip_dirent_torrent_normalize(&de);
index b5b9d273be4ba025b7b3bef0b7959ce95de2da0f..b9dac5c989e3276d6a2b94fe1628af5cc9ae20dc 100644 (file)
@@ -157,11 +157,17 @@ _zip_cdir_write(struct zip_cdir *cd, FILE *fp, struct zip_error *error)
 void
 _zip_dirent_finalize(struct zip_dirent *zde)
 {
-    free(zde->filename);
+    if (zde->filename_len > 0) {
+        free(zde->filename);
+    }
     zde->filename = NULL;
-    free(zde->extrafield);
+    if (zde->extrafield_len > 0) {
+        free(zde->extrafield);
+    }
     zde->extrafield = NULL;
-    free(zde->comment);
+    if (zde->comment_len > 0) {
+        free(zde->comment);
+    }
     zde->comment = NULL;
 }