]> granicus.if.org Git - php/commitdiff
Raise E_WARNING on PHP related errors
authorChristoph M. Becker <cmbecker69@gmx.de>
Tue, 20 Oct 2020 10:31:58 +0000 (12:31 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 26 Oct 2020 10:40:06 +0000 (11:40 +0100)
If Zip operations fails due to PHP error conditions before libzip even
has been called, there is no meaningful indication what failed; the
functions just return false, and the Zip status indicated that no error
did occur.  Therefore we raise `E_WARNING` in these cases.

Closes GH-6356.

ext/zip/php_zip.c
ext/zip/tests/bug64342_0.phpt
ext/zip/tests/bug64342_1-mb.phpt
ext/zip/tests/bug64342_1.phpt

index 96baabacd40fa77b7d5bb779449b5d22eb94872c..58707d6f952d1bc36148e762bc881b5f90a5dd5b 100644 (file)
@@ -288,11 +288,13 @@ static int php_zip_add_file(ze_zip_object *obj, const char *filename, size_t fil
        }
 
        if (!expand_filepath(filename, resolved_path)) {
+               php_error_docref(NULL, E_WARNING, "No such file or directory");
                return -1;
        }
 
        php_stat(resolved_path, strlen(resolved_path), FS_EXISTS, &exists_flag);
        if (Z_TYPE(exists_flag) == IS_FALSE) {
+               php_error_docref(NULL, E_WARNING, "No such file or directory");
                return -1;
        }
 
@@ -1163,6 +1165,7 @@ PHP_FUNCTION(zip_open)
        }
 
        if(!expand_filepath(ZSTR_VAL(filename), resolved_path)) {
+               php_error_docref(NULL, E_WARNING, "No such file or directory");
                RETURN_FALSE;
        }
 
@@ -1444,6 +1447,7 @@ PHP_METHOD(ZipArchive, open)
        }
 
        if (!(resolved_path = expand_filepath(ZSTR_VAL(filename), NULL))) {
+               php_error_docref(NULL, E_WARNING, "No such file or directory");
                RETURN_FALSE;
        }
 
index 43f60f5d7c5666381234064743c69649cb1d335f..751fb9c4ba4fa59ead2d197370a303644d91032a 100644 (file)
@@ -38,6 +38,8 @@ DONE
 ?>
 --EXPECTF--
 %s.txt
+
+Warning: ZipArchive::addFile(): No such file or directory in %s on line %d
 add failed
 close ok
 DONE
index 4884c9fe5f3978bf4ef470d78181f1c15f07e0d4..9efd046315eedd59ea65790de35c8e959b17c16e 100644 (file)
@@ -37,6 +37,7 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
 }
 @unlink($file);
 ?>
---EXPECT--
+--EXPECTF--
+Warning: ZipArchive::addFile(): No such file or directory in %s on line %d
 failed
 OK
index 6b923d3ef1abaf60f785e6d23fd9f3aa513701cc..1fff3da26d6a76fb834c4235611a491249055e37 100644 (file)
@@ -37,6 +37,7 @@ if ($zip->status == ZIPARCHIVE::ER_OK) {
 }
 @unlink($file);
 ?>
---EXPECT--
+--EXPECTF--
+Warning: ZipArchive::addFile(): No such file or directory in %s on line %d
 failed
 OK