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 @@ -55,6 +55,7 @@ PHP NEWS
55
55
- Zlib:
56
56
. Fixed bug GH-17745 (zlib extension incorrectly handles object arguments).
57
57
(nielsdos)
58
+ . Fix memory leak when encoding check fails. (nielsdos)
58
59
59
60
30 Jan 2025, PHP 8.4.4
60
61
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)
878
878
RETURN_THROWS ();
879
879
}
880
880
881
- if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
882
- RETURN_THROWS ();
883
- }
884
-
885
881
switch (encoding ) {
886
882
case PHP_ZLIB_ENCODING_RAW :
887
883
case PHP_ZLIB_ENCODING_GZIP :
@@ -892,6 +888,10 @@ PHP_FUNCTION(inflate_init)
892
888
RETURN_THROWS ();
893
889
}
894
890
891
+ if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
892
+ RETURN_THROWS ();
893
+ }
894
+
895
895
object_init_ex (return_value , inflate_context_ce );
896
896
ctx = Z_INFLATE_CONTEXT_P (return_value );
897
897
@@ -1131,10 +1131,6 @@ PHP_FUNCTION(deflate_init)
1131
1131
RETURN_THROWS ();
1132
1132
}
1133
1133
1134
- if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
1135
- RETURN_THROWS ();
1136
- }
1137
-
1138
1134
switch (encoding ) {
1139
1135
case PHP_ZLIB_ENCODING_RAW :
1140
1136
case PHP_ZLIB_ENCODING_GZIP :
@@ -1145,6 +1141,10 @@ PHP_FUNCTION(deflate_init)
1145
1141
RETURN_THROWS ();
1146
1142
}
1147
1143
1144
+ if (!zlib_create_dictionary_string (options , & dict , & dictlen )) {
1145
+ RETURN_THROWS ();
1146
+ }
1147
+
1148
1148
object_init_ex (return_value , deflate_context_ce );
1149
1149
ctx = Z_DEFLATE_CONTEXT_P (return_value );
1150
1150
You can’t perform that action at this time.
0 commit comments