File tree 3 files changed +29
-8
lines changed
3 files changed +29
-8
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ PHP NEWS
41
41
- Zlib:
42
42
. Fixed bug GH-17745 (zlib extension incorrectly handles object arguments).
43
43
(nielsdos)
44
+ . Fix memory leak when encoding check fails. (nielsdos)
44
45
45
46
13 Feb 2025, PHP 8.3.17
46
47
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 @@ -879,10 +879,6 @@ PHP_FUNCTION(inflate_init)
879
879
RETURN_THROWS ();
880
880
}
881
881
882
- if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
883
- RETURN_THROWS ();
884
- }
885
-
886
882
switch (encoding ) {
887
883
case PHP_ZLIB_ENCODING_RAW :
888
884
case PHP_ZLIB_ENCODING_GZIP :
@@ -893,6 +889,10 @@ PHP_FUNCTION(inflate_init)
893
889
RETURN_THROWS ();
894
890
}
895
891
892
+ if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
893
+ RETURN_THROWS ();
894
+ }
895
+
896
896
object_init_ex (return_value , inflate_context_ce );
897
897
ctx = Z_INFLATE_CONTEXT_P (return_value );
898
898
@@ -1132,10 +1132,6 @@ PHP_FUNCTION(deflate_init)
1132
1132
RETURN_THROWS ();
1133
1133
}
1134
1134
1135
- if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
1136
- RETURN_THROWS ();
1137
- }
1138
-
1139
1135
switch (encoding ) {
1140
1136
case PHP_ZLIB_ENCODING_RAW :
1141
1137
case PHP_ZLIB_ENCODING_GZIP :
@@ -1146,6 +1142,10 @@ PHP_FUNCTION(deflate_init)
1146
1142
RETURN_THROWS ();
1147
1143
}
1148
1144
1145
+ if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
1146
+ RETURN_THROWS ();
1147
+ }
1148
+
1149
1149
object_init_ex (return_value , deflate_context_ce );
1150
1150
ctx = Z_DEFLATE_CONTEXT_P (return_value );
1151
1151
You can’t perform that action at this time.
0 commit comments