Skip to content

Commit 4ef1053

Browse files
committed
initial fix
1 parent 4592d1c commit 4ef1053

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

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

ext/zlib/zlib.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1115,8 +1115,14 @@ PHP_FUNCTION(deflate_init)
11151115
}
11161116

11171117
if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("strategy"))) != NULL) {
1118+
bool failed = false;
1119+
11181120
ZVAL_DEINDIRECT(option_buffer);
1119-
strategy = zval_get_long(option_buffer);
1121+
strategy = zval_try_get_long(option_buffer, &failed);
1122+
if (UNEXPECTED(failed)) {
1123+
zend_argument_type_error(2, "\"strategy\" option must be of type int, %s given", zend_zval_value_name(option_buffer));
1124+
RETURN_THROWS();
1125+
}
11201126
}
11211127
switch (strategy) {
11221128
case Z_FILTERED:

0 commit comments

Comments
 (0)