Skip to content

Commit b50f7c2

Browse files
committed
Merge branch 'PHP-8.4'
* PHP-8.4: Fix memory leak when handling a too long path in ZipArchive::addGlob() Fix uouv when handling empty options in ZipArchive::addGlob()
2 parents ea387fc + ecd2872 commit b50f7c2

File tree

3 files changed

+48
-2
lines changed

3 files changed

+48
-2
lines changed

ext/zip/php_zip.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,13 +353,13 @@ typedef struct {
353353
#endif
354354
} zip_options;
355355

356+
/* Expects opts to be zero-initialized. */
356357
static int php_zip_parse_options(HashTable *options, zip_options *opts)
357358
/* {{{ */
358359
{
359360
zval *option;
360361

361362
/* default values */
362-
memset(opts, 0, sizeof(zip_options));
363363
opts->flags = ZIP_FL_OVERWRITE;
364364
opts->comp_method = -1; /* -1 to not change default */
365365
#ifdef HAVE_ENCRYPTION
@@ -1736,7 +1736,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17361736
size_t path_len = 1;
17371737
zend_long glob_flags = 0;
17381738
HashTable *options = NULL;
1739-
zip_options opts;
1739+
zip_options opts = {0};
17401740
int found;
17411741
zend_string *pattern;
17421742

@@ -1800,6 +1800,9 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
18001800

18011801
if (opts.add_path) {
18021802
if ((opts.add_path_len + file_stripped_len) > MAXPATHLEN) {
1803+
if (basename) {
1804+
zend_string_release_ex(basename, 0);
1805+
}
18031806
php_error_docref(NULL, E_WARNING, "Entry name too long (max: %d, %zd given)",
18041807
MAXPATHLEN - 1, (opts.add_path_len + file_stripped_len));
18051808
zend_array_destroy(Z_ARR_P(return_value));
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
addGlob with empty options
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
8+
touch($file = __DIR__ . '/addglob_empty_options.zip');
9+
10+
$zip = new ZipArchive();
11+
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
12+
$zip->addGlob(__FILE__, 0, []);
13+
var_dump($zip->statIndex(0)['name'] === __FILE__);
14+
$zip->close();
15+
16+
?>
17+
--CLEAN--
18+
<?php
19+
@unlink(__DIR__ . '/addglob_empty_options.zip');
20+
?>
21+
--EXPECT--
22+
bool(true)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
--TEST--
2+
addGlob with too long add_path option
3+
--EXTENSIONS--
4+
zip
5+
--FILE--
6+
<?php
7+
8+
touch($file = __DIR__ . '/addglob_too_long_add_path.zip');
9+
10+
$zip = new ZipArchive();
11+
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
12+
$zip->addGlob(__FILE__, 0, ['add_path' => str_repeat('A', PHP_MAXPATHLEN - 2)]);
13+
$zip->close();
14+
15+
?>
16+
--CLEAN--
17+
<?php
18+
@unlink(__DIR__ . '/addglob_too_long_add_path.zip');
19+
?>
20+
--EXPECTF--
21+
Warning: ZipArchive::addGlob(): Entry name too long (max: %d, %d given) in %s on line %d

0 commit comments

Comments
 (0)