Skip to content

Commit 0b3a937

Browse files
committed
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. Closes GH-7760.
1 parent 778513f commit 0b3a937

File tree

4 files changed

+17
-8
lines changed

4 files changed

+17
-8
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ PHP NEWS
77
. Fixed bug #81585 (cached_chunks are not counted to real_size on shutdown).
88
(cmb)
99

10+
- Hash:
11+
. Fixed bug GH-7759 (Incorrect return types for hash() and hash_hmac()).
12+
(cmb)
13+
1014
- PDO_PGSQL:
1115
. Fixed error message allocation of PDO PgSQL. (SATO Kentaro)
1216

ext/hash/hash.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
/** @generate-function-entries */
44

5-
function hash(string $algo, string $data, bool $binary = false): string|false {}
5+
function hash(string $algo, string $data, bool $binary = false): string {}
66

77
function hash_file(string $algo, string $filename, bool $binary = false): string|false {}
88

9-
function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string|false {}
9+
function hash_hmac(string $algo, string $data, string $key, bool $binary = false): string {}
1010

1111
function hash_hmac_file(string $algo, string $data, string $key, bool $binary = false): string|false {}
1212

ext/hash/hash_arginfo.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* This is a generated file, edit the .stub.php file instead.
2-
* Stub hash: 9352e0ac98e2ac53dc15d5024f9ef0c8092c4e9c */
2+
* Stub hash: f73c6fa1a4ac1ca93f87775bbe69fbdb2deb5746 */
33

4-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash, 0, 2, MAY_BE_STRING|MAY_BE_FALSE)
4+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash, 0, 2, IS_STRING, 0)
55
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
66
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
77
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
1313
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
1414
ZEND_END_ARG_INFO()
1515

16-
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_hmac, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
16+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_hash_hmac, 0, 3, IS_STRING, 0)
1717
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
1818
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
1919
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
2020
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
2121
ZEND_END_ARG_INFO()
2222

23-
#define arginfo_hash_hmac_file arginfo_hash_hmac
23+
ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_hash_hmac_file, 0, 3, MAY_BE_STRING|MAY_BE_FALSE)
24+
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)
25+
ZEND_ARG_TYPE_INFO(0, data, IS_STRING, 0)
26+
ZEND_ARG_TYPE_INFO(0, key, IS_STRING, 0)
27+
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, binary, _IS_BOOL, 0, "false")
28+
ZEND_END_ARG_INFO()
2429

2530
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_hash_init, 0, 1, HashContext, 0)
2631
ZEND_ARG_TYPE_INFO(0, algo, IS_STRING, 0)

ext/opcache/Optimizer/zend_func_info.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,9 @@ static const func_info_t func_infos[] = {
581581
F1("ob_gzhandler", MAY_BE_FALSE | MAY_BE_STRING),
582582

583583
/* ext/hash */
584-
F1("hash", MAY_BE_FALSE | MAY_BE_STRING),
584+
F1("hash", MAY_BE_STRING),
585585
F1("hash_file", MAY_BE_FALSE | MAY_BE_STRING),
586-
F1("hash_hmac", MAY_BE_FALSE | MAY_BE_STRING),
586+
F1("hash_hmac", MAY_BE_STRING),
587587
F1("hash_hmac_algos", MAY_BE_ARRAY | MAY_BE_ARRAY_KEY_LONG | MAY_BE_ARRAY_OF_STRING),
588588
F1("hash_hmac_file", MAY_BE_FALSE | MAY_BE_STRING),
589589
F1("hash_hkdf", MAY_BE_STRING),

0 commit comments

Comments
 (0)