Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 55f7303

Browse filesBrowse files
committed
ext/zip: fix memory leak when encryption is passed as userland array option.
Similar issue fixed in GH-19936. close GH-20363
1 parent be8c8a9 commit 55f7303
Copy full SHA for 55f7303

File tree

Expand file treeCollapse file tree

3 files changed

+61
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+61
-0
lines changed
Open diff view settings
Collapse file

‎NEWS‎

Copy file name to clipboardExpand all lines: NEWS
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ PHP NEWS
9595
. Fix GH-19722 (_get_osfhandle asserts in debug mode when given a socket).
9696
(dktapps)
9797

98+
- Zip:
99+
. Fix memory leak when passing enc_method/enc_password is passed as option
100+
for ZipArchive::addGlob()/addPattern() and with consecutive calls.
101+
(David Carlier)
102+
98103
23 Oct 2025, PHP 8.3.27
99104

100105
- Core:
Collapse file

‎ext/zip/php_zip.c‎

Copy file name to clipboardExpand all lines: ext/zip/php_zip.c
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,11 @@ static void php_zip_add_from_pattern(INTERNAL_FUNCTION_PARAMETERS, int type) /*
18321832
}
18331833
#ifdef HAVE_ENCRYPTION
18341834
if (opts.enc_method >= 0) {
1835+
if (UNEXPECTED(zip_file_set_encryption(ze_obj->za, ze_obj->last_id, ZIP_EM_NONE, NULL) < 0)) {
1836+
zend_array_destroy(Z_ARR_P(return_value));
1837+
php_error_docref(NULL, E_WARNING, "password reset failed");
1838+
RETURN_FALSE;
1839+
}
18351840
if (zip_file_set_encryption(ze_obj->za, ze_obj->last_id, opts.enc_method, opts.enc_password)) {
18361841
zend_array_destroy(Z_ARR_P(return_value));
18371842
RETURN_FALSE;
Collapse file

‎ext/zip/tests/oo_addglob_leak.phpt‎

Copy file name to clipboard
+51Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
--TEST--
2+
ZipArchive::addGlob() method leaking after several calls when encryption is set.
3+
--EXTENSIONS--
4+
zip
5+
--SKIPIF--
6+
<?php
7+
if (!method_exists('ZipArchive', 'setEncryptionName')) die('skip encrytion not supported');
8+
if(!defined("GLOB_BRACE")) die ('skip requires GLOB_BRACE');
9+
?>
10+
--FILE--
11+
<?php
12+
$dirname = __DIR__ . '/';
13+
include $dirname . 'utils.inc';
14+
15+
$dirname = __DIR__ . '/__tmp_oo_addglob2/';
16+
$file = $dirname . 'test.zip';
17+
18+
@mkdir($dirname);
19+
copy(__FILE__, $dirname . 'foo.txt');
20+
copy(__FILE__, $dirname . 'bar.txt');
21+
22+
$zip = new ZipArchive();
23+
if (!$zip->open($file, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
24+
exit('failed');
25+
}
26+
27+
$options = [
28+
'remove_all_path' => true,
29+
'comp_method' => ZipArchive::CM_STORE,
30+
'comp_flags' => 5,
31+
'enc_method' => ZipArchive::EM_AES_256,
32+
'enc_password' => 'secret',
33+
];
34+
var_dump($zip->addGlob($dirname . 'bar.*', GLOB_BRACE, $options));
35+
var_dump($zip->addGlob($dirname . 'bar.*', GLOB_BRACE, $options));
36+
?>
37+
--CLEAN--
38+
<?php
39+
$dirname = __DIR__ . '/';
40+
include $dirname . 'utils.inc';
41+
rmdir_rf(__DIR__ . '/__tmp_oo_addglob2/');
42+
?>
43+
--EXPECTF--
44+
array(1) {
45+
[0]=>
46+
string(%d) "%s"
47+
}
48+
array(1) {
49+
[0]=>
50+
string(%d) "%s"
51+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.