Skip to content

Commit 91c6c72

Browse files
committed
Fix memory leak when handling a too long path in ZipArchive::addGlob()
Closes GH-18330.
1 parent 0a6326c commit 91c6c72

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ PHP NEWS
4545

4646
- Zip:
4747
. Fix uouv when handling empty options in ZipArchive::addGlob(). (nielsdos)
48+
. Fix memory leak when handling a too long path in ZipArchive::addGlob().
49+
(nielsdos)
4850

4951
10 Apr 2025, PHP 8.3.20
5052

ext/zip/php_zip.c

+3
Original file line numberDiff line numberDiff line change
@@ -1796,6 +1796,9 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
17961796

17971797
if (opts.add_path) {
17981798
if ((opts.add_path_len + file_stripped_len) > MAXPATHLEN) {
1799+
if (basename) {
1800+
zend_string_release_ex(basename, 0);
1801+
}
17991802
php_error_docref(NULL, E_WARNING, "Entry name too long (max: %d, %zd given)",
18001803
MAXPATHLEN - 1, (opts.add_path_len + file_stripped_len));
18011804
zend_array_destroy(Z_ARR_P(return_value));
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)