Skip to content
Closed
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
18 changes: 18 additions & 0 deletions ext/zlib/tests/gh22142.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--TEST--
GH-22142: deflate_init() handles undefined variable without assertion failure
--FILE--
<?php

try {
$cls = new LibXMLError();
deflate_init($fusion, $cls);
} catch (\Throwable $e) {
echo $e::class, ": ", $e->getMessage(), "\n";
}

?>
--EXPECTF--
Warning: Undefined variable $fusion in %s on line %d

Deprecated: deflate_init(): Passing null to parameter #1 ($encoding) of type int is deprecated in %s on line %d
TypeError: deflate_init(): Argument #2 ($options) the value for option "level" must be of type int, null given
11 changes: 11 additions & 0 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,17 @@ ZEND_ATTRIBUTE_NONNULL static bool zlib_get_long_option(HashTable *options, cons

/* The |H ZPP specifier may leave HashTable entries wrapped in IS_INDIRECT. */
ZVAL_DEINDIRECT(option_buffer);
if (UNEXPECTED(Z_TYPE_P(option_buffer) == IS_UNDEF)) {
zend_argument_type_error(
2,
"the value for option \"%.*s\" must be of type int, %s given",
(int) option_name_len,
option_name,
zend_zval_value_name(option_buffer)
);
return false;
}

*value = zval_try_get_long(option_buffer, &failed);
if (UNEXPECTED(failed)) {
zend_argument_type_error(
Expand Down
Loading