]> granicus.if.org Git - php/commitdiff
- temp fix for a segfault happening when one adds two entries with
authorPierre Joye <pajoye@php.net>
Sun, 13 Aug 2006 00:52:59 +0000 (00:52 +0000)
committerPierre Joye <pajoye@php.net>
Sun, 13 Aug 2006 00:52:59 +0000 (00:52 +0000)
  the same name

ext/zip/TODO
ext/zip/php_zip.c

index c1baba97edb321897dee679d5ee077324cc86dc3..cb540ce7afaa0ec318356309687f3a07f19cf4b1 100644 (file)
@@ -1,3 +1,4 @@
+- fix _zip_replace (add two entries with the same name segfaults)
 - add pattern support to extract or add files
 - stream to add or modify entries
 - crypt support for zip (read and write)
index 96b8e4d578977f3316b2126072fb29214403ed88..d405ffd44f9f6fbf5d2529e462a4a61ca10b91f6 100644 (file)
@@ -956,6 +956,7 @@ ZIPARCHIVE_METHOD(addFile)
        int entry_name_len = 0;
        struct zip_source *zs;
        long offset_start = 0, offset_len = 0;
+       int cur_idx;
 
        if (!this) {
                RETURN_FALSE;
@@ -987,7 +988,23 @@ ZIPARCHIVE_METHOD(addFile)
        if (!zs) {
                RETURN_FALSE;
        }
-       if (zip_add(intern, entry_name, zs) < 0) {
+
+       cur_idx = zip_name_locate(intern, (const char *)entry_name, 0);
+       /* TODO: fix  _zip_replace */
+       if (cur_idx<0) {
+               /* reset the error */
+               if (intern->error.str) {
+                       _zip_error_fini(&intern->error);
+               }
+               _zip_error_init(&intern->error);
+
+       } else {
+               if (zip_delete(intern, cur_idx) == -1) {
+                       RETURN_FALSE;
+               }
+       }
+
+       if (zip_add(intern, entry_name, zs) == -1) {
                RETURN_FALSE;
        } else {
                RETURN_TRUE;
@@ -1006,6 +1023,7 @@ ZIPARCHIVE_METHOD(addFromString)
        ze_zip_object *ze_obj;
        struct zip_source *zs;
        int pos = 0;
+       int cur_idx;
 
        if (!this) {
                RETURN_FALSE;
@@ -1037,8 +1055,25 @@ ZIPARCHIVE_METHOD(addFromString)
                RETURN_FALSE;
        }
 
+       cur_idx = zip_name_locate(intern, (const char *)name, 0);
+       /* TODO: fix  _zip_replace */
+       if (cur_idx<0) {
+               /* reset the error */
+               if (intern->error.str) {
+                       _zip_error_fini(&intern->error);
+               }
+               _zip_error_init(&intern->error);
+
+       } else {
+               if (zip_delete(intern, cur_idx) == -1) {
+                       RETURN_FALSE;
+               }
+       }
+
        if (zip_add(intern, name, zs) == -1) {
                RETURN_FALSE;
+       } else {
+               RETURN_TRUE;
        }
 }
 /* }}} */