Skip to content

Commit ecd2872

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

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

Diff for: NEWS

+5
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,11 @@ PHP NEWS
5757
. Address deprecated PHP 8.4 session options to prevent test failures.
5858
(willvar)
5959

60+
- Zip:
61+
. Fix uouv when handling empty options in ZipArchive::addGlob(). (nielsdos)
62+
. Fix memory leak when handling a too long path in ZipArchive::addGlob().
63+
(nielsdos)
64+
6065
10 Apr 2025, PHP 8.4.6
6166

6267
- BCMath:

Diff for: ext/zip/php_zip.c

+5-2
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
@@ -1738,7 +1738,7 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17381738
size_t path_len = 1;
17391739
zend_long glob_flags = 0;
17401740
HashTable *options = NULL;
1741-
zip_options opts;
1741+
zip_options opts = {0};
17421742
int found;
17431743
zend_string *pattern;
17441744

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

18031803
if (opts.add_path) {
18041804
if ((opts.add_path_len + file_stripped_len) > MAXPATHLEN) {
1805+
if (basename) {
1806+
zend_string_release_ex(basename, 0);
1807+
}
18051808
php_error_docref(NULL, E_WARNING, "Entry name too long (max: %d, %zd given)",
18061809
MAXPATHLEN - 1, (opts.add_path_len + file_stripped_len));
18071810
zend_array_destroy(Z_ARR_P(return_value));

Diff for: ext/zip/tests/addGlob_empty_options.phpt

+22
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)

Diff for: ext/zip/tests/addGlob_too_long_add_path_option.phpt

+21
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)