Commit 7a3d889ad8e for php.net
commit 7a3d889ad8ef0f3425b83653f96e3649065e5930
Author: Weilin Du <108666168+LamentXU123@users.noreply.github.com>
Date: Thu Apr 30 21:41:39 2026 +0800
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().
diff --git a/NEWS b/NEWS
index 3144cdf88c5..9d002531912 100644
--- a/NEWS
+++ b/NEWS
@@ -211,5 +211,7 @@ PHP NEWS
. deflate_init() now raises a TypeError when the value for option
"level", "memory", "window", or "strategy" is not of type int.
(Weilin Du)
+ . inflate_init() now raises a TypeError when the value for option
+ "window" 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 6777820642f..4942b6e88ed 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -111,6 +111,8 @@ PHP 8.6 UPGRADE NOTES
- Zlib:
. deflate_init() now raises a TypeError when the value for option
"level", "memory", "window", or "strategy" is not of type int.
+ . inflate_init() now raises a TypeError when the value for option
+ "window" is not of type int.
========================================
2. New Features
diff --git a/ext/zlib/tests/inflate_init_window_type_error.phpt b/ext/zlib/tests/inflate_init_window_type_error.phpt
new file mode 100644
index 00000000000..fbca3129681
--- /dev/null
+++ b/ext/zlib/tests/inflate_init_window_type_error.phpt
@@ -0,0 +1,16 @@
+--TEST--
+inflate_init(): window option type validation
+--EXTENSIONS--
+zlib
+--FILE--
+<?php
+
+try {
+ inflate_init(ZLIB_ENCODING_DEFLATE, ['window' => []]);
+} catch (TypeError $e) {
+ echo $e->getMessage(), PHP_EOL;
+}
+
+?>
+--EXPECT--
+inflate_init(): Argument #2 ($options) the value for option "window" must be of type int, array given
diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c
index b1ee09635e5..a57796b2c66 100644
--- a/ext/zlib/zlib.c
+++ b/ext/zlib/zlib.c
@@ -885,16 +885,14 @@ PHP_FUNCTION(inflate_init)
zend_long encoding, window = 15;
char *dict = NULL;
size_t dictlen = 0;
- HashTable *options = NULL;
- zval *option_buffer;
+ HashTable *options = (HashTable *) &zend_empty_array;
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "l|H", &encoding, &options)) {
RETURN_THROWS();
}
- if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
- ZVAL_DEINDIRECT(option_buffer);
- window = zval_get_long(option_buffer);
+ if (!zlib_get_long_option(options, ZEND_STRL("window"), &window)) {
+ RETURN_THROWS();
}
if (window < 8 || window > 15) {
zend_value_error("zlib window size (logarithm) (" ZEND_LONG_FMT ") must be within 8..15", window);