File tree Expand file tree Collapse file tree 3 files changed +29
-8
lines changed Expand file tree Collapse file tree 3 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,7 @@ PHP NEWS
5555- Zlib:
5656 . Fixed bug GH-17745 (zlib extension incorrectly handles object arguments).
5757 (nielsdos)
58+ . Fix memory leak when encoding check fails. (nielsdos)
5859
596030 Jan 2025, PHP 8.4.4
6061
Original file line number Diff line number Diff line change 1+ --TEST--
2+ Memory leak when passing a dictionary with invalid encoding
3+ --EXTENSIONS--
4+ zlib
5+ --FILE--
6+ <?php
7+ try {
8+ inflate_init (123456 , ["dictionary " => "dict " ]);
9+ } catch (ValueError $ e ) {
10+ echo $ e ->getMessage (), "\n" ;
11+ }
12+ try {
13+ deflate_init (123456 , ["dictionary " => "dict " ]);
14+ } catch (ValueError $ e ) {
15+ echo $ e ->getMessage (), "\n" ;
16+ }
17+ ?>
18+ --EXPECT--
19+ Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE
20+ deflate_init(): Argument #1 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE
Original file line number Diff line number Diff line change @@ -878,10 +878,6 @@ PHP_FUNCTION(inflate_init)
878878 RETURN_THROWS ();
879879 }
880880
881- if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
882- RETURN_THROWS ();
883- }
884-
885881 switch (encoding ) {
886882 case PHP_ZLIB_ENCODING_RAW :
887883 case PHP_ZLIB_ENCODING_GZIP :
@@ -892,6 +888,10 @@ PHP_FUNCTION(inflate_init)
892888 RETURN_THROWS ();
893889 }
894890
891+ if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
892+ RETURN_THROWS ();
893+ }
894+
895895 object_init_ex (return_value , inflate_context_ce );
896896 ctx = Z_INFLATE_CONTEXT_P (return_value );
897897
@@ -1131,10 +1131,6 @@ PHP_FUNCTION(deflate_init)
11311131 RETURN_THROWS ();
11321132 }
11331133
1134- if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
1135- RETURN_THROWS ();
1136- }
1137-
11381134 switch (encoding ) {
11391135 case PHP_ZLIB_ENCODING_RAW :
11401136 case PHP_ZLIB_ENCODING_GZIP :
@@ -1145,6 +1141,10 @@ PHP_FUNCTION(deflate_init)
11451141 RETURN_THROWS ();
11461142 }
11471143
1144+ if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
1145+ RETURN_THROWS ();
1146+ }
1147+
11481148 object_init_ex (return_value , deflate_context_ce );
11491149 ctx = Z_DEFLATE_CONTEXT_P (return_value );
11501150
You can’t perform that action at this time.
0 commit comments