From e76f98967e55a5e7d8d63f1f56c746ebd73c77ae Mon Sep 17 00:00:00 2001 From: David Carlier Date: Fri, 5 Dec 2025 22:24:31 +0000 Subject: [PATCH] ext/zlib: minor internal changes. - consolidate encoding error exception b/w inflate_init()/deflate_init(). - dictionary option is supposed to be packed. --- ext/zlib/tests/inflate_init_error.phpt | 2 +- ext/zlib/tests/leak_invalid_encoding_with_dict.phpt | 2 +- ext/zlib/zlib.c | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ext/zlib/tests/inflate_init_error.phpt b/ext/zlib/tests/inflate_init_error.phpt index 8faed763be4e5..9854f7453909b 100644 --- a/ext/zlib/tests/inflate_init_error.phpt +++ b/ext/zlib/tests/inflate_init_error.phpt @@ -13,4 +13,4 @@ try { ?> --EXPECT-- -Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE +inflate_init(): Argument #1 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE diff --git a/ext/zlib/tests/leak_invalid_encoding_with_dict.phpt b/ext/zlib/tests/leak_invalid_encoding_with_dict.phpt index da2a11849c0c2..507e6842cb587 100644 --- a/ext/zlib/tests/leak_invalid_encoding_with_dict.phpt +++ b/ext/zlib/tests/leak_invalid_encoding_with_dict.phpt @@ -16,5 +16,5 @@ try { } ?> --EXPECT-- -Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE +inflate_init(): Argument #1 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE deflate_init(): Argument #1 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE diff --git a/ext/zlib/zlib.c b/ext/zlib/zlib.c index 0b08cea7d69ec..ae73efb747ed0 100644 --- a/ext/zlib/zlib.c +++ b/ext/zlib/zlib.c @@ -807,12 +807,17 @@ static bool zlib_create_dictionary_string(HashTable *options, char **dict, size_ HashTable *dictionary = Z_ARR_P(option_buffer); bool result = true; + if (!HT_IS_PACKED(dictionary)) { + zend_argument_value_error(2, "must be of type array with keys as integer"); + return false; + } + if (zend_hash_num_elements(dictionary) > 0) { zend_string **strings = safe_emalloc(zend_hash_num_elements(dictionary), sizeof(zend_string *), 0); size_t total = 0; zval *cur; - ZEND_HASH_FOREACH_VAL(dictionary, cur) { + ZEND_HASH_PACKED_FOREACH_VAL(dictionary, cur) { zend_string *string = zval_try_get_string(cur); if (string == NULL) { result = false; @@ -887,7 +892,7 @@ PHP_FUNCTION(inflate_init) case PHP_ZLIB_ENCODING_DEFLATE: break; default: - zend_value_error("Encoding mode must be ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP or ZLIB_ENCODING_DEFLATE"); + zend_argument_value_error(1, "must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE"); RETURN_THROWS(); }