php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81426 Regression in finfo_open
Submitted: 2021-09-08 21:24 UTC Modified: 2021-09-11 13:17 UTC
From: weierophinney@php.net Assigned: ab (profile)
Status: Not a bug Package: Filesystem function related
PHP Version: 8.1.0RC1 OS: Ubuntu 20.04
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: weierophinney@php.net
New email:
PHP Version: OS:

 

 [2021-09-08 21:24 UTC] weierophinney@php.net
Description:
------------
When supplying a MAGIC file to finfo_open, valid MAGIC files that were parsed correctly in PHP 7.3 - 8.0 now result in parse errors within the finfo extension.

An example of a MAGIC file that was working previously: https://raw.githubusercontent.com/laminas/laminas-validator/2.15.x/test/File/_files/magic.7.mime

The above file has been used in unit tests since the 5.6 series without issue; we only began seeing the issues when attempting to test against PHP 8.1rc1.

Test script:
---------------
$finfo = finfo_open(FILEINFO_MIME_TYPE, 'magic.7.mime'); // file referenced in Description section
echo finfo_file($finfo, 'plain.txt'); // assuming plain.txt is a text file

Expected result:
----------------
text/plain; charset=us-ascii

Actual result:
--------------
PHP Warning:  finfo_open(): Unparsable number `a                \b C.S0050-0 V1.0' in php shell code on line 1

Warning: finfo_open(): Unparsable number `a             \b C.S0050-0 V1.0' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `b                \b C.S0050-0-A V1.0.0' in php shell code on line 1

Warning: finfo_open(): Unparsable number `b             \b C.S0050-0-A V1.0.0' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `c                \b C.S0050-0-B V1.0' in php shell code on line 1

Warning: finfo_open(): Unparsable number `c             \b C.S0050-0-B V1.0' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b, contains[@0x%x]: ' in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b: ' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b: ' in php shell code on line 1
PHP Warning:  finfo_open(): Overflow for numeric type `leshort' value 0x223e9f78 in php shell code on line 1

Warning: finfo_open(): Overflow for numeric type `leshort' value 0x223e9f78 in php shell code on line 1
PHP Warning:  finfo_open(): `name       pgpkey' entries can only be declared at top level in php shell code on line 1

Warning: finfo_open(): `name    pgpkey' entries can only be declared at top level in php shell code on line 1
PHP Warning:  finfo_open(): Unparsable number `\b number=%d' in php shell code on line 1

Warning: finfo_open(): Unparsable number `\b number=%d' in php shell code on line 1
PHP Warning:  finfo_open(): Failed to load magic database at "magic.7.mime" in php shell code on line 1

Warning: finfo_open(): Failed to load magic database at "magic.7.mime" in php shell code on line 1


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-08 23:04 UTC] ramsey@php.net
I did a little digging around to see where this issue might have been introduced. We ported libmagic to 5.40 in 8.1, and I wonder if this might have introduced a regression: https://github.com/php/php-src/commit/3b9173dc8f3bda99e87003f6b6b2a16fa25c1b72
 [2021-09-08 23:15 UTC] ramsey@php.net
-Assigned To: +Assigned To: ab
 [2021-09-11 13:17 UTC] ab@php.net
-Status: Assigned +Status: Not a bug
 [2021-09-11 13:17 UTC] ab@php.net
Thanks for the report and further investigation. There are no guarantees on the magic data format compatibility whatsoever. A general recommendation is to omit usage of an external magic data.

Thanks
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 03 06:01:34 2025 UTC