[php-src] Issue #24289: finfo::file(): empty $filename ValueError reports argument #2 ($flags)

From: Date: Tue, 13 Oct 2026 09:37:50 +0000
Subject: [php-src] Issue #24289: finfo::file(): empty $filename ValueError reports argument #2 ($flags)
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-252983@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/24289 Author: lacatoire finfo::file() reports the wrong argument when $filename is empty. ```php <?php $finfo = new finfo(); try { finfo_file($finfo, ''); } catch (Throwable $e) { echo "procedural: ", $e::class, ': ', $e->getMessage(), "\n"; } try { $finfo->file(''); } catch (Throwable $e) { echo "method: ", $e::class, ': ', $e->getMessage(), "\n"; } ``` Output on PHP 8.4.x and 8.5.x: ``` procedural: ValueError: finfo_file(): Argument #2 ($filename) must not be empty method: ValueError: finfo::file(): Argument #2 ($flags) must not be empty ``` (8.3 prints the same with "cannot be empty".) Expected for the method: finfo::file(): Argument #1 ($filename) must not be empty. The same C function serves both finfo_file($finfo, $filename, ...) and finfo::file($filename, $flags, ...), and the argument number is hardcoded: - master and PHP-8.5, ext/fileinfo/fileinfo.c, PHP_FUNCTION(finfo_file): zend_argument_must_not_be_empty_error(2); - PHP-8.4, php_finfo_get_type(): buffer_param_num = (mimetype_emu ? 1 : 2) is used for both the empty check and the null byte check, so on 8.4 the null byte TypeError of the method names $flags too. A possible fix is to pass getThis() ? 1 : 2 (the null byte check on master and 8.5 is already correct, as it goes through zend_parse_method_parameters()). finfo_file_001.phpt only covers the procedural form.

« previous php.bugs (#252983) next »