Skip to content
Merged
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
2 changes: 1 addition & 1 deletion ext/hash/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 10 additions & 0 deletions ext/hash/tests/hash_file_error.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand All @@ -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
Expand Down
Loading