From 4ef1053522bd4799aa4c096d76ff5f7834693222 Mon Sep 17 00:00:00 2001 From: lamentxu <1372449351@qq.com> Date: Thu, 23 Apr 2026 19:21:44 +0800 Subject: [PATCH 1/3] initial fix --- .../tests/deflate_init_strategy_type_error.phpt | 16 ++++++++++++++++ ext/zlib/zlib.c | 8 +++++++- 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 ext/zlib/tests/deflate_init_strategy_type_error.phpt diff --git a/ext/zlib/tests/deflate_init_strategy_type_error.phpt b/ext/zlib/tests/deflate_init_strategy_type_error.phpt new file mode 100644 index 000000000000..8b86cda0d852 --- /dev/null +++ b/ext/zlib/tests/deflate_init_strategy_type_error.phpt @@ -0,0 +1,16 @@ +--TEST-- +deflate_init(): strategy option type validation +--EXTENSIONS-- +zlib +--FILE-- + []]); +} catch (TypeError $e) { + echo $e->getMessage(), PHP_EOL; +} + +?> +--EXPECT-- +deflate_init(): Argument #2 ($options) "strategy" option must be of type int, array given diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index dbbaf1a24157..86e8309857b5 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1115,8 +1115,14 @@ PHP_FUNCTION(deflate_init) } if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("strategy"))) != NULL) { + bool failed = false; + ZVAL_DEINDIRECT(option_buffer); - strategy = zval_get_long(option_buffer); + strategy = zval_try_get_long(option_buffer, &failed); + if (UNEXPECTED(failed)) { + zend_argument_type_error(2, "\"strategy\" option must be of type int, %s given", zend_zval_value_name(option_buffer)); + RETURN_THROWS(); + } } switch (strategy) { case Z_FILTERED: From 98c40b08cbefe21248ab5dd6b879e783604149f9 Mon Sep 17 00:00:00 2001 From: lamentxu <1372449351@qq.com> Date: Thu, 23 Apr 2026 21:27:26 +0800 Subject: [PATCH 2/3] [skip ci] better wording, NEWS and UPGRADING --- NEWS | 4 ++++ UPGRADING | 4 ++++ ext/zlib/tests/deflate_init_strategy_type_error.phpt | 2 +- ext/zlib/zlib.c | 2 +- 4 files changed, 10 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index 18d12d02dbbe..fd927b668297 100644 --- a/NEWS +++ b/NEWS @@ -197,4 +197,8 @@ PHP NEWS . Added ZipArchive::openString() method. (Tim Starling, Soner Sayakci, Ghaith Olabi) +- Zlib: + . deflate_init() now raises a TypeError when the "strategy" element + in $options is not of type int. (Weilin Du) + <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/UPGRADING b/UPGRADING index f24ea681be2e..fb2cebd6bf5d 100644 --- a/UPGRADING +++ b/UPGRADING @@ -101,6 +101,10 @@ PHP 8.6 UPGRADE NOTES files argument if one or more of the entries is not a string. +- Zlib: + . deflate_init() now raises a TypeError when the "strategy" element + in $options is not of type int. + ======================================== 2. New Features ======================================== diff --git a/ext/zlib/tests/deflate_init_strategy_type_error.phpt b/ext/zlib/tests/deflate_init_strategy_type_error.phpt index 8b86cda0d852..91e8939c241d 100644 --- a/ext/zlib/tests/deflate_init_strategy_type_error.phpt +++ b/ext/zlib/tests/deflate_init_strategy_type_error.phpt @@ -13,4 +13,4 @@ try { ?> --EXPECT-- -deflate_init(): Argument #2 ($options) "strategy" option must be of type int, array given +deflate_init(): Argument #2 ($options) the "strategy" element in $options must be of type int, array given diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 86e8309857b5..378abd95bf0a 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1120,7 +1120,7 @@ PHP_FUNCTION(deflate_init) ZVAL_DEINDIRECT(option_buffer); strategy = zval_try_get_long(option_buffer, &failed); if (UNEXPECTED(failed)) { - zend_argument_type_error(2, "\"strategy\" option must be of type int, %s given", zend_zval_value_name(option_buffer)); + zend_argument_type_error(2, "the \"strategy\" element in $options must be of type int, %s given", zend_zval_value_name(option_buffer)); RETURN_THROWS(); } } From da759f12d0d5fdb2484a8425b3a1ee1c57981e17 Mon Sep 17 00:00:00 2001 From: lamentxu <1372449351@qq.com> Date: Thu, 23 Apr 2026 21:45:05 +0800 Subject: [PATCH 3/3] [skip ci] better wording --- NEWS | 4 ++-- UPGRADING | 4 ++-- ext/zlib/tests/deflate_init_strategy_type_error.phpt | 2 +- ext/zlib/zlib.c | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/NEWS b/NEWS index fd927b668297..d26148877670 100644 --- a/NEWS +++ b/NEWS @@ -198,7 +198,7 @@ PHP NEWS (Tim Starling, Soner Sayakci, Ghaith Olabi) - Zlib: - . deflate_init() now raises a TypeError when the "strategy" element - in $options is not of type int. (Weilin Du) + . deflate_init() now raises a TypeError when the value for option + "strategy" is not of type int. (Weilin Du) <<< NOTE: Insert NEWS from last stable release here prior to actual release! >>> diff --git a/UPGRADING b/UPGRADING index fb2cebd6bf5d..6c6115ebcc84 100644 --- a/UPGRADING +++ b/UPGRADING @@ -102,8 +102,8 @@ PHP 8.6 UPGRADE NOTES a string. - Zlib: - . deflate_init() now raises a TypeError when the "strategy" element - in $options is not of type int. + . deflate_init() now raises a TypeError when the value for option + "strategy" is not of type int. ======================================== 2. New Features diff --git a/ext/zlib/tests/deflate_init_strategy_type_error.phpt b/ext/zlib/tests/deflate_init_strategy_type_error.phpt index 91e8939c241d..0227d1bf6c29 100644 --- a/ext/zlib/tests/deflate_init_strategy_type_error.phpt +++ b/ext/zlib/tests/deflate_init_strategy_type_error.phpt @@ -13,4 +13,4 @@ try { ?> --EXPECT-- -deflate_init(): Argument #2 ($options) the "strategy" element in $options must be of type int, array given +deflate_init(): Argument #2 ($options) the value for option "strategy" must be of type int, array given diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 378abd95bf0a..115eedbc894a 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -1120,7 +1120,7 @@ PHP_FUNCTION(deflate_init) ZVAL_DEINDIRECT(option_buffer); strategy = zval_try_get_long(option_buffer, &failed); if (UNEXPECTED(failed)) { - zend_argument_type_error(2, "the \"strategy\" element in $options must be of type int, %s given", zend_zval_value_name(option_buffer)); + zend_argument_type_error(2, "the value for option \"strategy\" must be of type int, %s given", zend_zval_value_name(option_buffer)); RETURN_THROWS(); } }