]> granicus.if.org Git - php/commitdiff
Fix UNKNOWN default values in ext/zip
authorMáté Kocsis <kocsismate@woohoolabs.com>
Sun, 3 May 2020 09:49:31 +0000 (11:49 +0200)
committerMáté Kocsis <kocsismate@woohoolabs.com>
Wed, 6 May 2020 17:15:34 +0000 (19:15 +0200)
ext/zip/php_zip.c
ext/zip/php_zip.stub.php
ext/zip/php_zip_arginfo.h

index 2d3b3c3107ca3f02e54d12b15132142ceaf51b0a..dc6031228506b2846cf4afb278cc8c8c767dd775 100644 (file)
@@ -1725,6 +1725,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
                php_error_docref(NULL, E_NOTICE, "Empty string as pattern");
                RETURN_FALSE;
        }
+       if (options && zend_hash_num_elements(Z_ARRVAL_P(options)) > 0 && (php_zip_parse_options(options, &opts) < 0)) {
                RETURN_FALSE;
        }
 
@@ -2302,9 +2303,7 @@ static ZIPARCHIVE_METHOD(setEncryptionName)
        char *name, *password = NULL;
        size_t name_len, password_len;
 
-       ZIP_FROM_OBJECT(intern, self);
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s",
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s!",
                        &name, &name_len, &method, &password, &password_len) == FAILURE) {
                RETURN_THROWS();
        }
@@ -2337,14 +2336,14 @@ static ZIPARCHIVE_METHOD(setEncryptionIndex)
        char *password = NULL;
        size_t password_len;
 
-
-       if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s",
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s!",
                        &index, &method, &password, &password_len) == FAILURE) {
                RETURN_THROWS();
        }
 
-       if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
        ZIP_FROM_OBJECT(intern, self);
+
+       if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
                RETURN_FALSE;
        }
        RETURN_TRUE;
@@ -2766,6 +2765,7 @@ static ZIPARCHIVE_METHOD(extractTo)
        size_t pathto_len;
        int ret;
 
+       if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|z", &pathto, &pathto_len, &zval_files) == FAILURE) {
                RETURN_THROWS();
        }
 
@@ -2776,10 +2776,10 @@ static ZIPARCHIVE_METHOD(extractTo)
        }
 
        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;
-                       }
+               ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
+               if (!ret) {
+                       RETURN_FALSE;
+               }
        }
 
        if (zval_files && Z_TYPE_P(zval_files) != IS_NULL) {
index 101afcbe8ee490d033d4915cdaab447d02b50234..e7aabe2c6c20ba3592abef531a338f15ebaf0b22 100644 (file)
@@ -64,16 +64,16 @@ class ZipArchive
     public function addFromString(string $name, string $content, int $flags = ZipArchive::FL_OVERWRITE) {}
 
     /** @return bool */
-    public function addFile(string $filepath, string $entryname = UNKNOWN, int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE) {}
+    public function addFile(string $filepath, string $entryname = "", int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE) {}
 
     /** @return bool */
     public function replaceFile(string $filepath, string $index, int $start = 0, int $length = 0, int $flags = 0) {}
 
     /** @return array|false */
-    public function addGlob(string $pattern, int $flags = 0, $options = UNKNOWN) {}
+    public function addGlob(string $pattern, int $flags = 0, array $options = []) {}
 
     /** @return array|false */
-    public function addPattern(string $pattern, string $path = UNKNOWN, $options = UNKNOWN) {}
+    public function addPattern(string $pattern, string $path = ".", array $options = []) {}
 
     /** @return bool */
     public function renameIndex(int $index, string $new_name) {}
@@ -138,7 +138,7 @@ class ZipArchive
     public function unchangeName(string $name) {}
 
     /** @return bool */
-    public function extractTo(string $pathto, $files = UNKNOWN) {}
+    public function extractTo(string $pathto, $files = null) {}
 
     /** @return string|false */
     public function getFromName(string $entryname, int $len = 0, int $flags = 0) {}
@@ -171,10 +171,10 @@ class ZipArchive
 
 #ifdef HAVE_ENCRYPTION
     /** @return bool */
-    public function setEncryptionName(string $name, int $method, string $password = UNKNOWN) {}
+    public function setEncryptionName(string $name, int $method, ?string $password = null) {}
 
     /** @return bool */
-    public function setEncryptionIndex(int $index, int $method, string $password = UNKNOWN) {}
+    public function setEncryptionIndex(int $index, int $method, ?string $password = null) {}
 #endif
 
 #ifdef HAVE_PROGRESS_CALLBACK
index ac392ef517449e041baabb5f6983cd11b6a1c0f9..31d816851880bda9c223fe9b63403080ad65df82 100644 (file)
@@ -68,7 +68,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addFile, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, filepath, IS_STRING, 0)
-       ZEND_ARG_TYPE_INFO(0, entryname, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, entryname, IS_STRING, 0, "\"\"")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "0")
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "ZipArchive::FL_OVERWRITE")
@@ -85,13 +85,13 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addGlob, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
-       ZEND_ARG_INFO(0, options)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addPattern, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
-       ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
-       ZEND_ARG_INFO(0, options)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 0, "\".\"")
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_renameIndex, 0, 0, 2)
@@ -174,7 +174,7 @@ ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_extractTo, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, pathto, IS_STRING, 0)
-       ZEND_ARG_INFO(0, files)
+       ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, files, "null")
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_getFromName, 0, 0, 1)
@@ -245,7 +245,7 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setEncryptionName, 0, 0, 2)
        ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0)
-       ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
 ZEND_END_ARG_INFO()
 #endif
 
@@ -253,7 +253,7 @@ ZEND_END_ARG_INFO()
 ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setEncryptionIndex, 0, 0, 2)
        ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
        ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0)
-       ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
 ZEND_END_ARG_INFO()
 #endif