]> granicus.if.org Git - php/commitdiff
- Fixed bug #53603 (ZipArchive should quiet stat errors).
authorGustavo André dos Santos Lopes <cataphract@php.net>
Fri, 24 Dec 2010 22:38:36 +0000 (22:38 +0000)
committerGustavo André dos Santos Lopes <cataphract@php.net>
Fri, 24 Dec 2010 22:38:36 +0000 (22:38 +0000)
#It is unclear if url_stat handlers should emit a warning in case
#PHP_STREAM_URL_STAT_QUIET is not specified and the resource does
#not exist. Most url_stat handlers never emit messages; the plain
#one does only so in the extraordinary event of an open_basedir
#restriction.
#But in case, php_stat uses PHP_STREAM_URL_STAT_QUIET for the
#FS_EXISTS, which suggests that mere checks on file existence are
#supposed to use this flag (arguably).
#The downside is that important diagnostic messages might be
#omitted.

NEWS
ext/zip/php_zip.c
ext/zip/tests/bug53603.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index cdc8cd8a70b33104d12f20cac0a8a6e14b37223c..3492a8f166b11560a7ddacd0627933571553c124 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -91,6 +91,8 @@
   . Fixed bug #53568 (swapped memset arguments in struct initialization).
     (crrodriguez at opensuse dot org)
   . Fixed bug #53579 (stream_get_contents() segfaults on ziparchive streams) (Hannes)
+  . Fixed bug #53603 (ZipArchive should quiet stat errors). (brad dot froehle at
+    gmail dot com, Gustavo)
 
 09 Dec 2010, PHP 5.3.4
 - Upgraded bundled Sqlite3 to version 3.7.3. (Ilia)
index 1b42c94457d92022da58d403ff086adaa8f95506..45784a1169e6f17833195ffa0e296d520a6e6fe1 100644 (file)
@@ -196,7 +196,7 @@ static int php_zip_extract_file(struct zip * za, char *dest, char *file, int fil
        }
 
        /* let see if the path already exists */
-       if (php_stream_stat_path(file_dirname_fullpath, &ssb) < 0) {
+       if (php_stream_stat_path_ex(file_dirname_fullpath, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
 
 #if defined(PHP_WIN32) && (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION == 1)
                char *e;
@@ -2378,7 +2378,7 @@ static ZIPARCHIVE_METHOD(extractTo)
                RETURN_FALSE;
        }
 
-       if (php_stream_stat_path(pathto, &ssb) < 0) {
+       if (php_stream_stat_path_ex(pathto, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
                ret = php_stream_mkdir(pathto, 0777,  PHP_STREAM_MKDIR_RECURSIVE, NULL);
                if (!ret) {
                        RETURN_FALSE;
diff --git a/ext/zip/tests/bug53603.phpt b/ext/zip/tests/bug53603.phpt
new file mode 100644 (file)
index 0000000..7be20dc
--- /dev/null
@@ -0,0 +1,38 @@
+--TEST--
+Bug #53603 (ZipArchive should quiet stat errors)
+--SKIPIF--
+<?php
+if(!extension_loaded('zip')) die('skip');
+?>
+--FILE--
+<?php
+
+class TestStream {
+       function url_stat($path, $flags) {
+               if (!($flags & STREAM_URL_STAT_QUIET))
+                       trigger_error("not quiet");
+               return array();
+       }
+}
+
+stream_wrapper_register("teststream", "TestStream");
+
+$dirname = dirname(__FILE__) . '/';
+$file = $dirname . 'test_with_comment.zip';
+$zip = new ZipArchive;
+if ($zip->open($file) !== TRUE) {
+       echo "open failed.\n";
+       exit('failed');
+}
+
+$a = $zip->extractTo('teststream://test');
+var_dump($a);
+
+--EXPECTF--
+Warning: ZipArchive::extractTo(teststream://test/foo): failed to open stream: "TestStream::stream_open" call failed in %s on line %d
+
+Warning: ZipArchive::extractTo(teststream://test/bar): failed to open stream: "TestStream::stream_open" call failed in %s on line %d
+
+Warning: ZipArchive::extractTo(teststream://test/foobar/baz): failed to open stream: "TestStream::stream_open" call failed in %s on line %d
+bool(true)
+