File tree Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Open diff view settings
Expand file tree Collapse file tree 3 files changed +61
-0
lines changed Open diff view settings
Original file line number Diff line number Diff 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+
9810323 Oct 2025, PHP 8.3.27
99104
100105- Core:
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments