diff --git a/ext/hash/hash.c b/ext/hash/hash.c index d57ae149691b..4a0b0c49437e 100644 --- a/ext/hash/hash.c +++ b/ext/hash/hash.c @@ -361,7 +361,7 @@ static void php_hash_do_hash( } if (isfilename) { if (zend_char_has_nul_byte(data, data_len)) { - zend_argument_value_error(1, "must not contain any null bytes"); + zend_argument_value_error(2, "must not contain any null bytes"); RETURN_THROWS(); } stream = php_stream_open_wrapper_ex(data, "rb", REPORT_ERRORS, NULL, FG(default_context)); diff --git a/ext/hash/tests/hash_file_error.phpt b/ext/hash/tests/hash_file_error.phpt index a381d3bdd63c..4ef84a62ddf4 100644 --- a/ext/hash/tests/hash_file_error.phpt +++ b/ext/hash/tests/hash_file_error.phpt @@ -19,6 +19,13 @@ try { echo $exception::class, ': ', $exception->getMessage(), "\n"; } +echo "\n-- Testing hash_file() function with a null byte in the filename --\n"; +try { + hash_file('md5', $filename . chr(0) . $filename); +} catch (Throwable $e) { + echo $e::class, ': ', $e->getMessage(), "\n"; +} + echo "\n-- Testing hash_file() function with a non-existent file --\n"; var_dump(hash_file('md5', 'nonexistent.txt')); @@ -36,6 +43,9 @@ unlink( $filename ); -- Testing hash_file() function with an unknown algorithm -- ValueError: hash_file(): Argument #1 ($algo) must be a valid hashing algorithm +-- Testing hash_file() function with a null byte in the filename -- +ValueError: hash_file(): Argument #2 ($filename) must not contain any null bytes + -- Testing hash_file() function with a non-existent file -- Warning: hash_file(): Failed to open stream: No such file or directory in %s on line %d