1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Fix memory leak when handling a too long path in ZipArchive::addGlob()

Closes GH-18330.
This commit is contained in:
Niels Dossche
2025-04-15 23:59:25 +02:00
parent 0a6326c6ac
commit 91c6c727d5
3 changed files with 26 additions and 0 deletions

2
NEWS
View File

@@ -45,6 +45,8 @@ PHP NEWS
- Zip:
. Fix uouv when handling empty options in ZipArchive::addGlob(). (nielsdos)
. Fix memory leak when handling a too long path in ZipArchive::addGlob().
(nielsdos)
10 Apr 2025, PHP 8.3.20

View File

@@ -1796,6 +1796,9 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
if (opts.add_path) {
if ((opts.add_path_len + file_stripped_len) > MAXPATHLEN) {
if (basename) {
zend_string_release_ex(basename, 0);
}
php_error_docref(NULL, E_WARNING, "Entry name too long (max: %d, %zd given)",
MAXPATHLEN - 1, (opts.add_path_len + file_stripped_len));
zend_array_destroy(Z_ARR_P(return_value));

View File

@@ -0,0 +1,21 @@
--TEST--
addGlob with too long add_path option
--EXTENSIONS--
zip
--FILE--
<?php
touch($file = __DIR__ . '/addglob_too_long_add_path.zip');
$zip = new ZipArchive();
$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE);
$zip->addGlob(__FILE__, 0, ['add_path' => str_repeat('A', PHP_MAXPATHLEN - 2)]);
$zip->close();
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/addglob_too_long_add_path.zip');
?>
--EXPECTF--
Warning: ZipArchive::addGlob(): Entry name too long (max: %d, %d given) in %s on line %d