From 8982ef3321c20b532f7f45d031586a3615a7e4e8 Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 11 Dec 2021 19:09:41 +0100 Subject: [PATCH 1/2] Fix GH-7759: Incorrect return types for hash() and hash_hmac() `hash()` and `hash_hmac()` never return `false`; only `hash_file()` and `hash_hmac_file()` return `false` in case the data cannot be read. --- ext/hash/hash.stub.php | 4 ++-- ext/hash/hash_arginfo.h | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/ext/hash/hash.stub.php b/ext/hash/hash.stub.php index c0d4cbca7c3d5..250fb68ee4e9f 100644 --- a/ext/hash/hash.stub.php +++ b/ext/hash/hash.stub.php @@ -2,11 +2,11 @@ /** @generate-function-entries */ -function hash(string $algo, string $data, bool $binary = false): string|false {} +function hash(string $algo, string $data, bool $binary = false): string {} function hash_file(string $algo, string $filename, bool $binary = false): string|false {} -function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string|false {} +function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string {} function hash_hmac_file(string $algo, string $data, string $key, bool $binary = false): string|false {} diff --git a/ext/hash/hash_arginfo.h b/ext/hash/hash_arginfo.h index db043da97b477..5aef2c11d1d61 100644 --- a/ext/hash/hash_arginfo.h +++ b/ext/hash/hash_arginfo.h @@ -1,7 +1,7 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 9352e0ac98e2ac53dc15d5024f9ef0c8092c4e9c */ + * Stub hash: f73c6fa1a4ac1ca93f87775bbe69fbdb2deb5746 */ -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash, 0, 2, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash, 0, 2, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false") @@ -13,14 +13,19 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_file, 0, 2, MAY_BE_STRING|M ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_hmac, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash_hmac, 0, 3, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false") ZEND_END_ARG_INFO() -#define arginfo_hash_hmac_file arginfo_hash_hmac +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_hmac_file, 0, 3, MAY_BE_STRING|MAY_BE_FALSE) + ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false") +ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_hash_init, 0, 1, HashContext, 0) ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0) From 2eaf8cf47f4681cbedca3177748a4952c9721b2e Mon Sep 17 00:00:00 2001 From: "Christoph M. Becker" Date: Sat, 11 Dec 2021 22:16:00 +0100 Subject: [PATCH 2/2] Adjust optimizer func info --- ext/opcache/Optimizer/zend_func_info.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/opcache/Optimizer/zend_func_info.c b/ext/opcache/Optimizer/zend_func_info.c index 3589aa1b3c2ef..84c9d20966cae 100644 --- a/ext/opcache/Optimizer/zend_func_info.c +++ b/ext/opcache/Optimizer/zend_func_info.c @@ -581,9 +581,9 @@ static const func_info_t func_infos[] = { F1("ob_gzhandler", MAY_BE_FALSE | MAY_BE_STRING), /* ext/hash */ - F1("hash", MAY_BE_FALSE | MAY_BE_STRING), + F1("hash", MAY_BE_STRING), F1("hash_file", MAY_BE_FALSE | MAY_BE_STRING), - F1("hash_hmac", MAY_BE_FALSE | MAY_BE_STRING), + F1("hash_hmac", MAY_BE_STRING), F1("hash_hmac_algos", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING), F1("hash_hmac_file", MAY_BE_FALSE | MAY_BE_STRING), F1("hash_hkdf", MAY_BE_STRING),