[php-src] Issue #21069: Test finfo_buffer() function : basic functionality

[email protected] (ArchMaster2024)
Newsgroups php.bugs
Message-ID <iwpl8V2mMr5KqzWAIA3Lb2vid8MYfSkVPzdCRdBmjzs@main.internal.php.net>
Issue: https://github.com/php/php-src/issues/21069
Author: ArchMaster2024

### Description

The following code:

```php
$magicFile = __DIR__ . DIRECTORY_SEPARATOR . 'magic私はガラスを食べられます';

$options = array(
    FILEINFO_NONE,
    FILEINFO_MIME,
);

$buffers = array(
    "Regular string here",
    "\177ELF",
    "\000\000\0001\000\000\0000\000\000\0000\000\000\0002\000\000\0000\000\000\0000\000\000\0003",
    "\x55\x7A\x6E\x61",
    "id=ImageMagick\x0a\x0c\x0a:\x1a",
    "RIFFüîò^BAVI LISTv",
);

echo "*** Testing finfo_buffer() : basic functionality ***\n";

foreach( $options as $option ) {
    $finfo = finfo_open( $option, $magicFile );
    foreach( $buffers as $string ) {
        var_dump( finfo_buffer( $finfo, $string, $option ) );
    }
    finfo_close( $finfo );
}

<?php
```

Resulted in this output:
```
*** Testing finfo_buffer() : basic functionality ***

Warning: finfo_open(/test_php/source/php/ext/fileinfo/tests/magic私はガラスを食べられます): Failed to open stream: No such file or directory in /test_php/source/php/ext/fileinfo/tests/finfo_buffer_basic-mb.php on line 21

Warning: finfo_open(/test_php/source/php/ext/fileinfo/tests/magic私はガラスを食べられます): Failed to open stream: No such file or directory in /test_php/source/php/ext/fileinfo/tests/finfo_buffer_basic-mb.php on line 21

Warning: finfo_open(): Failed to load magic database at "/test_php/source/php/ext/fileinfo/tests/magic私はガラスを食べられます" in /test_php/source/php/ext/fileinfo/tests/finfo_buffer_basic-mb.php on line 21

Fatal error: Uncaught TypeError: finfo_buffer(): Argument #1 ($finfo) must be of type finfo, false given in /test_php/source/php/ext/fileinfo/tests/finfo_buffer_basic-mb.php:23
Stack trace:
#0 /test_php/source/php/ext/fileinfo/tests/finfo_buffer_basic-mb.php(23): finfo_buffer(false, 'Regular string ...', 0)
#1 {main}
  thrown in /test_php/source/php/ext/fileinfo/tests/finfo_buffer_basic-mb.php on line 23
```

But I expected this output instead:
```
*** Testing finfo_buffer() : basic functionality ***
string(36) "ASCII text, with no line terminators"
string(3) "ELF"
string(22) "old ACE/gr binary file"
string(12) "xo65 object,"
string(15) "MIFF image data"
string(25) "RIFF (little-endian) data"
string(28) "text/plain; charset=us-ascii"
string(26) "text/plain; charset=ebcdic"
string(40) "application/octet-stream; charset=binary"
string(28) "text/plain; charset=us-ascii"
string(28) "image/x-miff; charset=binary"
string(25) "text/plain; charset=utf-8"
```


### PHP Version

```plain
PHP 8.4.17RC1 (cli) (built: Jan 25 2026 21:1817) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.4.17RC1, Copyright (c) Zend Technologies
```

### Operating System

Debian GNU/Linux 12 (bookworm) x86_64 (container run with podman)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.