Skip to content

finfo::file(): empty $filename ValueError reports argument #2 ($flags) #24289

Closed

Description

@lacatoire

finfo::file() reports the wrong argument when $filename is empty.

<?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.

Activity

  1. added a commit that references this issue on Oct 13, 2026
    19a5060
  2. added 3 commits that reference this issue on Oct 13, 2026
    06c95e7
    9b7efbc
    41256a0
  3. added a commit that references this issue on Oct 15, 2026
    57ad95f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions