pajoye          Sun Jun  3 21:30:12 2007 UTC

  Modified files:              
    /php-src/ext/zip    php_zip.c 
    /php-src/ext/zip/tests      bug11216.phpt 
  Log:
  - MFB: PECL #11216, addEmptyDir crashes if the directory already exists 
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/php_zip.c?r1=1.44&r2=1.45&diff_format=u
Index: php-src/ext/zip/php_zip.c
diff -u php-src/ext/zip/php_zip.c:1.44 php-src/ext/zip/php_zip.c:1.45
--- php-src/ext/zip/php_zip.c:1.44      Sat May 19 22:26:32 2007
+++ php-src/ext/zip/php_zip.c   Sun Jun  3 21:30:12 2007
@@ -16,7 +16,7 @@
   +----------------------------------------------------------------------+
 */
 
-/* $Id: php_zip.c,v 1.44 2007/05/19 22:26:32 pajoye Exp $ */
+/* $Id: php_zip.c,v 1.45 2007/06/03 21:30:12 pajoye Exp $ */
 
 #ifdef HAVE_CONFIG_H
 #include "config.h"
@@ -996,6 +996,9 @@
        zval *this = getThis();
        char *dirname;
        int   dirname_len;
+       int idx;
+       struct zip_stat sb;
+       char *s;
 
        if (!this) {
                RETURN_FALSE;
@@ -1007,14 +1010,39 @@
                        &dirname, &dirname_len, UG(ascii_conv)) == FAILURE) {
                return;
        }
+
        if (dirname_len<1) {
                RETURN_FALSE;
        }
 
-       if (zip_add_dir(intern, (const char *)dirname) < 0) {
-               RETURN_FALSE;
+    if (dirname[dirname_len-1] != '/') {
+               s=(char *)emalloc(dirname_len+2);
+               strcpy(s, dirname);
+               s[dirname_len] = '/';
+               s[dirname_len+1] = '\0';
+    } else {
+               s = dirname;
+       }
+
+       idx = zip_stat(intern, s, 0, &sb);
+       if (idx >= 0) {
+               RETVAL_FALSE;
+       } else {
+               /* reset the error */
+               if (intern->error.str) {
+                       _zip_error_fini(&intern->error);
+               }
+               _zip_error_init(&intern->error);
+
+               if (zip_add_dir(intern, (const char *)s) == -1) {
+                       RETVAL_FALSE;
+               }
+               RETVAL_TRUE;
+       }
+
+       if (s != dirname) {
+               efree(s);
        }
-       RETURN_TRUE;
 }
 /* }}} */
 
@@ -2116,7 +2144,7 @@
        php_info_print_table_start();
 
        php_info_print_table_row(2, "Zip", "enabled");
-       php_info_print_table_row(2, "Extension Version","$Id: php_zip.c,v 1.44 
2007/05/19 22:26:32 pajoye Exp $");
+       php_info_print_table_row(2, "Extension Version","$Id: php_zip.c,v 1.45 
2007/06/03 21:30:12 pajoye Exp $");
        php_info_print_table_row(2, "Zip version", "2.0.0");
        php_info_print_table_row(2, "Libzip version", "0.7.1");
 
http://cvs.php.net/viewvc.cgi/php-src/ext/zip/tests/bug11216.phpt?r1=1.1&r2=1.2&diff_format=u
Index: php-src/ext/zip/tests/bug11216.phpt
diff -u /dev/null php-src/ext/zip/tests/bug11216.phpt:1.2
--- /dev/null   Sun Jun  3 21:30:12 2007
+++ php-src/ext/zip/tests/bug11216.phpt Sun Jun  3 21:30:12 2007
@@ -0,0 +1,28 @@
+--TEST--
+Bug #11216 (::addEmptyDir() crashes when the directory already exists)
+--SKIPIF--
+<?php
+/* $Id: bug11216.phpt,v 1.2 2007/06/03 21:30:12 pajoye Exp $ */
+if(!extension_loaded('zip')) die('skip');
+ ?>
+--FILE--
+<?php
+$archive = new ZipArchive();
+$archive->open('__test.zip', ZIPARCHIVE::CREATE);
+var_dump($archive->addEmptyDir('test'));
+print_r($archive);
+var_dump($archive->addEmptyDir('test'));
+$archive->close();
+unlink('__test.zip');
+?>
+--EXPECT--
+bool(true)
+ZipArchive Object
+(
+    [status] => 0
+    [statusSys] => 0
+    [numFiles] => 1
+    [filename] => 
+    [comment] => 
+)
+bool(false)

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to