Skip to content

finfo_file() fatal error message incorrect on empty filename argument. #15752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
danielmorell opened this issue Sep 4, 2024 · 2 comments
Closed

Comments

@danielmorell
Copy link

Description

The following code:

<?php
$info = finfo_open(FILEINFO_MIME_TYPE);

if ($info) {
    echo finfo_file($info, '') . PHP_EOL;
}

Resulted in this output:

PHP Fatal error:  Uncaught ValueError: finfo_file(): Argument #1 ($finfo) cannot be empty in /some/dir/example.php:5

But I expected this output instead:

PHP Fatal error:  Uncaught ValueError: finfo_file(): Argument #2 ($filename) cannot be empty in /some/dir/example.php:5

The empty second argument is miss-attributed in the error message to the first argument.

If a non-empty string e.g. "foo" is passed as the second filename argument this error does not occur.

PHP Version

PHP 8.1-8.3

Operating System

Ubuntu 18.04

@DanielEScherzer
Copy link
Member

Caused by the wrong parameter to zend_argument_value_error() (8.2, 8.3) or zend_argument_must_not_be_empty_error() (8.4) in _php_finfo_get_type()

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 4, 2024
Show the correct parameter name and number - the error is caused by the second
parameter being empty, not the first.
@DanielEScherzer
Copy link
Member

Patch at #15755

DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 4, 2024
Show the correct parameter names and numbers - the errors are caused by the
second parameter being empty or having null bytes, not the first.
DanielEScherzer added a commit to DanielEScherzer/php-src that referenced this issue Sep 4, 2024
Show the correct parameter names and numbers - the errors are caused by the
second parameter being empty or having null bytes, not the first.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants