Skip to content

Commit c5686d8

Browse files
committed
Fix UNKNOWN default values in ext/zip
1 parent 51517ee commit c5686d8

File tree

3 files changed

+25
-23
lines changed

3 files changed

+25
-23
lines changed

ext/zip/php_zip.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,6 +1725,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17251725
php_error_docref(NULL, E_NOTICE, "Empty string as pattern");
17261726
RETURN_FALSE;
17271727
}
1728+
if (options && zend_hash_num_elements(Z_ARRVAL_P(options)) > 0 && (php_zip_parse_options(options, &opts) < 0)) {
17281729
RETURN_FALSE;
17291730
}
17301731

@@ -2302,9 +2303,7 @@ static ZIPARCHIVE_METHOD(setEncryptionName)
23022303
char *name, *password = NULL;
23032304
size_t name_len, password_len;
23042305

2305-
ZIP_FROM_OBJECT(intern, self);
2306-
2307-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s",
2306+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "sl|s!",
23082307
&name, &name_len, &method, &password, &password_len) == FAILURE) {
23092308
RETURN_THROWS();
23102309
}
@@ -2337,14 +2336,14 @@ static ZIPARCHIVE_METHOD(setEncryptionIndex)
23372336
char *password = NULL;
23382337
size_t password_len;
23392338

2340-
2341-
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s",
2339+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "ll|s!",
23422340
&index, &method, &password, &password_len) == FAILURE) {
23432341
RETURN_THROWS();
23442342
}
23452343

2346-
if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
23472344
ZIP_FROM_OBJECT(intern, self);
2345+
2346+
if (zip_file_set_encryption(intern, index, (zip_uint16_t)method, password)) {
23482347
RETURN_FALSE;
23492348
}
23502349
RETURN_TRUE;
@@ -2765,6 +2764,7 @@ static ZIPARCHIVE_METHOD(extractTo)
27652764
size_t pathto_len;
27662765
int ret;
27672766

2767+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "p|z", &pathto, &pathto_len, &zval_files) == FAILURE) {
27682768
RETURN_THROWS();
27692769
}
27702770

@@ -2773,13 +2773,15 @@ static ZIPARCHIVE_METHOD(extractTo)
27732773
}
27742774

27752775
if (php_stream_stat_path_ex(pathto, PHP_STREAM_URL_STAT_QUIET, &ssb, NULL) < 0) {
2776-
ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
2777-
if (!ret) {
2778-
RETURN_FALSE;
2779-
}
2776+
ret = php_stream_mkdir(pathto, 0777, PHP_STREAM_MKDIR_RECURSIVE, NULL);
2777+
if (!ret) {
2778+
RETURN_FALSE;
2779+
}
27802780
}
27812781

27822782
ZIP_FROM_OBJECT(intern, self);
2783+
2784+
if (zval_files && Z_TYPE_P(zval_files) != IS_NULL) {
27832785
uint32_t nelems, i;
27842786

27852787
switch (Z_TYPE_P(zval_files)) {

ext/zip/php_zip.stub.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ public function addEmptyDir(string $dirname, int $flags = 0) {}
6464
public function addFromString(string $name, string $content, int $flags = ZipArchive::FL_OVERWRITE) {}
6565

6666
/** @return bool */
67-
public function addFile(string $filepath, string $entryname = UNKNOWN, int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE) {}
67+
public function addFile(string $filepath, string $entryname = "", int $start = 0, int $length = 0, int $flags = ZipArchive::FL_OVERWRITE) {}
6868

6969
/** @return bool */
7070
public function replaceFile(string $filepath, string $index, int $start = 0, int $length = 0, int $flags = 0) {}
7171

7272
/** @return array|false */
73-
public function addGlob(string $pattern, int $flags = 0, $options = UNKNOWN) {}
73+
public function addGlob(string $pattern, int $flags = 0, array $options = []) {}
7474

7575
/** @return array|false */
76-
public function addPattern(string $pattern, string $path = UNKNOWN, $options = UNKNOWN) {}
76+
public function addPattern(string $pattern, string $path = ".", array $options = []) {}
7777

7878
/** @return bool */
7979
public function renameIndex(int $index, string $new_name) {}
@@ -138,7 +138,7 @@ public function unchangeIndex(int $index) {}
138138
public function unchangeName(string $name) {}
139139

140140
/** @return bool */
141-
public function extractTo(string $pathto, $files = UNKNOWN) {}
141+
public function extractTo(string $pathto, $files = null) {}
142142

143143
/** @return string|false */
144144
public function getFromName(string $entryname, int $len = 0, int $flags = 0) {}
@@ -171,10 +171,10 @@ public function setCompressionIndex(int $index, int $method, int $compflags = 0)
171171

172172
#ifdef HAVE_ENCRYPTION
173173
/** @return bool */
174-
public function setEncryptionName(string $name, int $method, string $password = UNKNOWN) {}
174+
public function setEncryptionName(string $name, int $method, ?string $password = null) {}
175175

176176
/** @return bool */
177-
public function setEncryptionIndex(int $index, int $method, string $password = UNKNOWN) {}
177+
public function setEncryptionIndex(int $index, int $method, ?string $password = null) {}
178178
#endif
179179

180180
#ifdef HAVE_PROGRESS_CALLBACK

ext/zip/php_zip_arginfo.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ ZEND_END_ARG_INFO()
6868

6969
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addFile, 0, 0, 1)
7070
ZEND_ARG_TYPE_INFO(0, filepath, IS_STRING, 0)
71-
ZEND_ARG_TYPE_INFO(0, entryname, IS_STRING, 0)
71+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, entryname, IS_STRING, 0, "\"\"")
7272
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, start, IS_LONG, 0, "0")
7373
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, length, IS_LONG, 0, "0")
7474
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "ZipArchive::FL_OVERWRITE")
@@ -85,13 +85,13 @@ ZEND_END_ARG_INFO()
8585
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addGlob, 0, 0, 1)
8686
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
8787
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, flags, IS_LONG, 0, "0")
88-
ZEND_ARG_INFO(0, options)
88+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
8989
ZEND_END_ARG_INFO()
9090

9191
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_addPattern, 0, 0, 1)
9292
ZEND_ARG_TYPE_INFO(0, pattern, IS_STRING, 0)
93-
ZEND_ARG_TYPE_INFO(0, path, IS_STRING, 0)
94-
ZEND_ARG_INFO(0, options)
93+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, path, IS_STRING, 0, "\".\"")
94+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, options, IS_ARRAY, 0, "[]")
9595
ZEND_END_ARG_INFO()
9696

9797
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_renameIndex, 0, 0, 2)
@@ -174,7 +174,7 @@ ZEND_END_ARG_INFO()
174174

175175
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_extractTo, 0, 0, 1)
176176
ZEND_ARG_TYPE_INFO(0, pathto, IS_STRING, 0)
177-
ZEND_ARG_INFO(0, files)
177+
ZEND_ARG_INFO_WITH_DEFAULT_VALUE(0, files, "null")
178178
ZEND_END_ARG_INFO()
179179

180180
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_getFromName, 0, 0, 1)
@@ -245,15 +245,15 @@ ZEND_END_ARG_INFO()
245245
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setEncryptionName, 0, 0, 2)
246246
ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0)
247247
ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0)
248-
ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0)
248+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
249249
ZEND_END_ARG_INFO()
250250
#endif
251251

252252
#if defined(HAVE_ENCRYPTION)
253253
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ZipArchive_setEncryptionIndex, 0, 0, 2)
254254
ZEND_ARG_TYPE_INFO(0, index, IS_LONG, 0)
255255
ZEND_ARG_TYPE_INFO(0, method, IS_LONG, 0)
256-
ZEND_ARG_TYPE_INFO(0, password, IS_STRING, 0)
256+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, password, IS_STRING, 1, "null")
257257
ZEND_END_ARG_INFO()
258258
#endif
259259

0 commit comments

Comments
 (0)