Skip to content

ext/hash: report argument #2 ($filename) for null bytes in hash_file() - #23534

Merged
devnexen merged 2 commits into
php:masterfrom
lacatoire:fix/hash-file-null-byte-arg-num
Sep 2, 2026
Merged

ext/hash: report argument #2 ($filename) for null bytes in hash_file()#23534
devnexen merged 2 commits into
php:masterfrom
lacatoire:fix/hash-file-null-byte-arg-num

Conversation

@lacatoire

@lacatoire lacatoire commented Sep 1, 2026

Copy link
Copy Markdown
Member

php_hash_do_hash() hardcodes argument index 1 in its isfilename branch, so hash_file() blames $algo for a null byte that was carried by $filename. hash_file() is the only caller passing isfilename = 1, and its filename is argument 2.

Before:

ValueError: hash_file(): Argument #1 ($algo) must not contain any null bytes

After:

ValueError: hash_file(): Argument #2 ($filename) must not contain any null bytes

php_hash_do_hash_hmac() already reports 2 for the same check, so hash_hmac_file() was right and hash_file() was the odd one out. Only the error message changes; a test case is added.

php_hash_do_hash() hardcodes argument index 1 in the isfilename branch,
so hash_file() blames $algo for a null byte carried by $filename.
hash_file() is the only caller passing isfilename = 1, and its filename
is argument #2; php_hash_do_hash_hmac() already uses 2 for the same
check.
Comment thread ext/hash/tests/hash_file_error.phpt Outdated
Co-authored-by: NickSdot <32384907+NickSdot@users.noreply.github.com>
@devnexen
devnexen merged commit df2090a into php:master Sep 2, 2026
17 of 18 checks passed
@lacatoire
lacatoire deleted the fix/hash-file-null-byte-arg-num branch September 2, 2026 06:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants