Skip to content

Commit 7a3d889

Browse files
authored
ext/zlib: Remove zval_get_long usage in inflate_init() (#21909)
This is a follow-up on the removal of the silent casts in deflate_init().
1 parent 1462499 commit 7a3d889

4 files changed

Lines changed: 23 additions & 5 deletions

File tree

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,5 +211,7 @@ PHP NEWS
211211
. deflate_init() now raises a TypeError when the value for option
212212
"level", "memory", "window", or "strategy" is not of type int.
213213
(Weilin Du)
214+
. inflate_init() now raises a TypeError when the value for option
215+
"window" is not of type int. (Weilin Du)
214216

215217
<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>

UPGRADING

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ PHP 8.6 UPGRADE NOTES
111111
- Zlib:
112112
. deflate_init() now raises a TypeError when the value for option
113113
"level", "memory", "window", or "strategy" is not of type int.
114+
. inflate_init() now raises a TypeError when the value for option
115+
"window" is not of type int.
114116

115117
========================================
116118
2. New Features
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
inflate_init(): window option type validation
3+
--EXTENSIONS--
4+
zlib
5+
--FILE--
6+
<?php
7+
8+
try {
9+
inflate_init(ZLIB_ENCODING_DEFLATE, ['window' => []]);
10+
} catch (TypeError $e) {
11+
echo $e->getMessage(), PHP_EOL;
12+
}
13+
14+
?>
15+
--EXPECT--
16+
inflate_init(): Argument #2 ($options) the value for option "window" must be of type int, array given

ext/zlib/zlib.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -885,16 +885,14 @@ PHP_FUNCTION(inflate_init)
885885
zend_long encoding, window = 15;
886886
char *dict = NULL;
887887
size_t dictlen = 0;
888-
HashTable *options = NULL;
889-
zval *option_buffer;
888+
HashTable *options = (HashTable *) &zend_empty_array;
890889

891890
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l|H", &encoding, &options)) {
892891
RETURN_THROWS();
893892
}
894893

895-
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
896-
ZVAL_DEINDIRECT(option_buffer);
897-
window = zval_get_long(option_buffer);
894+
if (!zlib_get_long_option(options, ZEND_STRL("window"), &window)) {
895+
RETURN_THROWS();
898896
}
899897
if (window < 8 || window > 15) {
900898
zend_value_error("zlib window size (logarithm) (" ZEND_LONG_FMT ") must be within 8..15", window);

0 commit comments

Comments
 (0)