Skip to content

Fix GH-17745: zlib extension incorrectly handles object arguments #17750

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
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
20 changes: 20 additions & 0 deletions ext/zlib/tests/gh17745.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
--TEST--
GH-17745 (zlib extension incorrectly handles object arguments)
--EXTENSIONS--
zlib
--FILE--
<?php
$obj = new stdClass;
$obj->level = 3;
var_dump(deflate_init(ZLIB_ENCODING_RAW, $obj));

class Options {
public int $level = 3;
}
var_dump(deflate_init(ZLIB_ENCODING_RAW, new Options));
?>
--EXPECT--
object(DeflateContext)#2 (0) {
}
object(DeflateContext)#3 (0) {
}
6 changes: 6 additions & 0 deletions ext/zlib/zlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,7 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_
zval *option_buffer;

if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("dictionary"))) != NULL) {
ZVAL_DEINDIRECT(option_buffer);
ZVAL_DEREF(option_buffer);
switch (Z_TYPE_P(option_buffer)) {
case IS_STRING: {
Expand Down Expand Up @@ -870,6 +871,7 @@ PHP_FUNCTION(inflate_init)
}

if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
ZVAL_DEINDIRECT(option_buffer);
window = zval_get_long(option_buffer);
}
if (window < 8 || window > 15) {
Expand Down Expand Up @@ -1088,6 +1090,7 @@ PHP_FUNCTION(deflate_init)
}

if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("level"))) != NULL) {
ZVAL_DEINDIRECT(option_buffer);
level = zval_get_long(option_buffer);
}
if (level < -1 || level > 9) {
Expand All @@ -1096,6 +1099,7 @@ PHP_FUNCTION(deflate_init)
}

if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("memory"))) != NULL) {
ZVAL_DEINDIRECT(option_buffer);
memory = zval_get_long(option_buffer);
}
if (memory < 1 || memory > 9) {
Expand All @@ -1104,6 +1108,7 @@ PHP_FUNCTION(deflate_init)
}

if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("window"))) != NULL) {
ZVAL_DEINDIRECT(option_buffer);
window = zval_get_long(option_buffer);
}
if (window < 8 || window > 15) {
Expand All @@ -1112,6 +1117,7 @@ PHP_FUNCTION(deflate_init)
}

if (options && (option_buffer = zend_hash_str_find(options, ZEND_STRL("strategy"))) != NULL) {
ZVAL_DEINDIRECT(option_buffer);
strategy = zval_get_long(option_buffer);
}
switch (strategy) {
Expand Down
4 changes: 2 additions & 2 deletions ext/zlib/zlib.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,11 +270,11 @@ function gzread($stream, int $length): string|false {}
*/
function gzgets($stream, ?int $length = null): string|false {}

function deflate_init(int $encoding, array $options = []): DeflateContext|false {}
function deflate_init(int $encoding, array|object $options = []): DeflateContext|false {}

function deflate_add(DeflateContext $context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string|false {}

function inflate_init(int $encoding, array $options = []): InflateContext|false {}
function inflate_init(int $encoding, array|object $options = []): InflateContext|false {}

function inflate_add(InflateContext $context, string $data, int $flush_mode = ZLIB_SYNC_FLUSH): string|false {}

Expand Down
6 changes: 3 additions & 3 deletions ext/zlib/zlib_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading