RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 858653 - fileinfo extension: use stat function from stream wrapper
Summary: fileinfo extension: use stat function from stream wrapper
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: php
Version: 6.3
Hardware: All
OS: Linux
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Remi Collet
QA Contact: Lukáš Zachar
URL:
Whiteboard:
Depends On:
Blocks: 869697
TreeView+ depends on / blocked
 
Reported: 2012-09-19 10:27 UTC by Jani Ollikainen
Modified: 2021-01-14 09:23 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
: 869697 (view as bug list)
Environment:
Last Closed: 2013-02-21 10:14:29 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
PHP Bug Tracker 54016 0 None None None 2012-09-19 10:27:30 UTC
Red Hat Product Errata RHSA-2013:0514 0 normal SHIPPED_LIVE Moderate: php security, bug fix and enhancement update 2013-02-20 21:29:20 UTC

Description Jani Ollikainen 2012-09-19 10:27:30 UTC
Description of problem:
PHP has broken Fileinfo that doesn't support wrappers even it has
context parameter for them.

Version-Release number of selected component (if applicable):
PHP 5.3.0-5.3.5

How reproducible:
Try to use Fileinfo to get info from some wrapper ex. http://

Steps to Reproduce:
<?php
$url="http://74.125.143.94/images/srpr/logo3w.png";
$finfo=new finfo(FILEINFO_MIME);
$str_mime = $finfo->file($url);
var_dump($str_mime);
?>

Actual results:
PHP Warning:  finfo::file(): File or path not found 'http://74.125.143.94/images/srpr/logo3w.png' in - on line 4
bool(false)

Expected results:
string(9) "image/png"

Additional info:
The old PECL Fileinfo module works, so if one installs that into RHEL5 it works, but as RHEL6 has Fileinfo itself which is broken, there's no nice way to
fix this (without just copying a working Fileinfo over the broken one, which is bad way).

Luckily this problem can be avoided by coding differently, but the problem is
all the existing systems which relies that it just works<tm>.

But that patch to fix it, would be nice to get into RHEL6.

Workaround:
<?php
$url="http://74.125.143.94/images/srpr/logo3w.png";
$finfo=new finfo(FILEINFO_MIME);
$str_mime=$finfo->buffer(file_get_contents($url));
var_dump($str_mime);
?>

Comment 1 Jani Ollikainen 2012-09-19 10:31:50 UTC
Forgot to mention about the workaround that of course it's very bad with big files as now the whole file is loaded to string before trying to figure out what it is. If one has big files, probably just reading max 1k of the file would be better and then giving that to buffer().

Comment 3 Joe Orton 2012-09-19 13:45:59 UTC
Hi, thanks for contacting us.

finfo::file() takes a filename argument by string.  Are some docs somewhere which say otherwise?

http://www.php.net/manual/en/function.finfo-file.php

Comment 4 Jani Ollikainen 2012-09-19 15:55:54 UTC
No, filename as a argument is a string. Filename can be URI as it's a string. You see similar documentation here: http://php.net/manual/en/function.file-get-contents.php

And the workaround uses that, which is documented as is that finfo-file, there's string for filename and context for stream wrappers.

Comment 5 Joe Orton 2012-09-20 07:53:01 UTC
Ah, thanks, sorry, I missed the upstream bug reference.

Fixed in http://svn.php.net/viewvc?view=revision&revision=308327

Comment 6 Remi Collet 2012-10-05 06:53:39 UTC
The linked upstream bug refers to "stream". Applying the upstream patch works for some stream wrappers (tested with zip, from upstream unit test).

Despite this patch, your test script doesn't work (even with latest upstream PHP version 5.4.8RC1). It seems http streams are curently not supported (need stat and seek capabilities)

Need more investigation.

Comment 7 Joe Orton 2012-10-05 07:31:02 UTC
Good point.  So there are two problems here:

1) the fileinfo extension does not use the stat interface from the stream wrapper.

2) the http stream wrapper does not support the stat interface

The upstream patch referenced above does fix (1), but not (2).  So it would fix use of e.g. zip:// URLs.  We can pull in that fix.

Jani, if you also require a fix for (2) can you file a new bug?  Supporting http stat is an enhancement request, we'd have to get a fix accepted upstream for that.

Comment 10 Joe Orton 2012-10-12 11:29:31 UTC
In fact my comment about the zip:// URLs was not correct for php 5.3.3; even the zip stream wrapper does not support the stat interface in that version of PHP.  

To ensure we are 100% clear about the scope of the fix for this bug, we are intending to fix here only part (1) mentioned in comment 7.

If stream wrapper support is required for other stream types, please file new enhancements bugs so we can track those requests separately.

Comment 14 errata-xmlrpc 2013-02-21 10:14:29 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

http://rhn.redhat.com/errata/RHSA-2013-0514.html


Note You need to log in before you can comment on or make changes to this bug.