Skip to content

finfo::buffer(): Failed identify data 0:(null) #13344

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
P2T opened this issue Feb 6, 2024 · 4 comments
Closed

finfo::buffer(): Failed identify data 0:(null) #13344

P2T opened this issue Feb 6, 2024 · 4 comments

Comments

@P2T
Copy link

P2T commented Feb 6, 2024

Description

The following code:

<?php
$data = pack('H*','fffe000000099999');
$mime_type = (new finfo(FILEINFO_MIME))->buffer($data);

Resulted in this output:

Warning: finfo::buffer(): Failed identify data 0:(null)

But I expected this output instead:
Something instead of '(null)'

PHP Version

PHP 8.3.2

Operating System

No response

@Girgias
Copy link
Member

Girgias commented Feb 7, 2024

I'm confused, why do you expect "something instead of null" here?

What does this data represent and how should it determined?

Anyway, this looks more like a feature request for the underling libmagic library: https://www.darwinsys.com/file/ or https://bugs.astron.com/my_view_page.php

@P2T
Copy link
Author

P2T commented Feb 7, 2024

I'm confused, why do you expect "something instead of null" here?

What does this data represent and how should it determined?

Anyway, this looks more like a feature request for the underling libmagic library: https://www.darwinsys.com/file/ or https://bugs.astron.com/my_view_page.php

I don't know the file format. The issue is the warning with the message "null".

Proposal 1: remove the warning, return false

Proposal 2: keep the warning, change (null) to a default message

Proposal 3: keep the warning, show an actual/useful message from the lib (only in this case, this ticket could be considered as a feature request for the lib).

@ranvis
Copy link
Contributor

ranvis commented Feb 8, 2024

@Girgias
The current libmagic (5.45) contains the update that fixes this case: file/file@029b824.

It appears that the identification error without error code/message is just the bug of the library.
Otherwise, error code and message should be returned from the library, as the manpage says magic_buffer() returns NULL on error.

@nielsdos
Copy link
Member

Thanks for figuring out the upstream commit.
I'll get it backported. Additionally, I prepared a PR to update 8.4-dev to libmagic 5.45.

nielsdos added a commit to nielsdos/php-src that referenced this issue Feb 11, 2024
Credits to ranvis for finding the upstream commit that fixes the issue.

This backports file/file@029b824
nielsdos added a commit that referenced this issue Feb 13, 2024
* PHP-8.2:
  Fix GH-13344: finfo::buffer(): Failed identify data 0:(null)
nielsdos added a commit that referenced this issue Feb 13, 2024
* PHP-8.3:
  Fix GH-13344: finfo::buffer(): Failed identify data 0:(null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants