Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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 value for option
"strategy" is not of type int. (Weilin Du)

<<< NOTE: Insert NEWS from last stable release here prior to actual release! >>>
4 changes: 4 additions & 0 deletions UPGRADING
Original file line number Diff line number Diff line change
Expand Up @@ -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 value for option
"strategy" is not of type int.

========================================
2. New Features
========================================
Expand Down
16 changes: 16 additions & 0 deletions ext/zlib/tests/deflate_init_strategy_type_error.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--TEST--
deflate_init(): strategy option type validation
--EXTENSIONS--
zlib
--FILE--
<?php

try {
deflate_init(ZLIB_ENCODING_DEFLATE, ['strategy' => []]);
} catch (TypeError $e) {
echo $e->getMessage(), PHP_EOL;
}

?>
--EXPECT--
deflate_init(): Argument #2 ($options) the value for option "strategy" must be of type int, array given
8 changes: 7 additions & 1 deletion ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "the value for option \"strategy\" must be of type int, %s given", zend_zval_value_name(option_buffer));
RETURN_THROWS();
}
}
switch (strategy) {
case Z_FILTERED:
Expand Down