Bug #74573 [Com]: finfo_file apk
| From: | 209721949 at qq dot com | Date: | Thu, 11 May 2017 16:07:43 +0000 |
| Subject: | Bug #74573 [Com]: finfo_file apk | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-209068@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74573&edit=1
ID: 74573
Comment by: 209721949 at qq dot com
Reported by: 209721949 at qq dot com
Summary: finfo_file apk
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: mac
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
since .apk file has it's own mime type, i think it's better to get the right mime type
directly and correct, just like other types of file, can it be implemented in the future ï¼
Previous Comments:
------------------------------------------------------------------------
[2017-05-11 15:48:52] spam2 at rhsoft dot net
> requinix@php.net: .apk files are ZIP archives
yeah, openoffice documents are ZIP files too *but* they are recognized because it's the
underlying libmagic - *maybe* for that case it's true and a recent libmagic would have the same
result
but be careful to classify that as "not a bug"
with current head from https://github.com/zendtech/php-src /just beause also
test the experimental JIT at the same time
a) "php ext/fileinfo/create_data_file.php" against a Fedora 25 libmagic works
b) the sample from https://bugs.php.net/bug.php?id=67516 is correctly
detected as image/gif and no longer application/octet-stream
c) it is proven that fileinfo in PHP is broken by deign for years
------------------------------------------------------------------------
[2017-05-11 15:36:21] spam2 at rhsoft dot net
just tested it again with PHP 7.1.5
"/usr/bin/php ext/fileinfo/create_data_file.php /usr/share/misc/magic.mgc >
ext/fileinfo/data_file.c" *only seems* to work
happily i included a large testsuite in our pgo-build and stop rpmbuild when it fails, no need for
complete gcc-profiling and second buildstage when the result is a broken PHP, see below
________________________________________________________
frankly as i reported the bug i waited at least 2 years in the hope fileinfo get any updates,
nothing.... so we have for at least 4 years a known image/gif detected as application/octet-stream
which makes any verification of useruploads pointless when you need to allow
"application/octet-stream"
you case with "zip" is harmless, at least you can distinct it form a random executable :-)
[harry@srv-rhsoft:/data/lounge-daten/php-mimtype-bug]$ php mime.php
/mnt/data/lounge-daten/php-mimtype-bug/1.gif
/usr/bin/file -b --mime-type
image/gif
finfo_file(filename, FILEINFO_MIME_TYPE)
application/octet-stream
________________________________________________________
FAILED: NOT ALL TESTS PASSED
[11-May-2017 17:31:22 Europe/Vienna] PHP Warning: finfo_open(): Failed to load magic database at
'(null)'. in /Volumes/dune/www-servers/cms/cms/autotests/api_captcha.php on line 39
[11-May-2017 17:31:22 Europe/Vienna] CMS-AUTOTEST: cl_api->captcha->test() failed - TypeError:
finfo_file() expects parameter 1 to be resource, boolean given in
/Volumes/dune/www-servers/cms/cms/autotests/api_captcha.php:40
Stack trace:
#0 /Volumes/dune/www-servers/cms/cms/autotests/api_captcha.php(40): finfo_file(false,
'/Volumes/dune/w...', 16)
#1 /Volumes/dune/www-servers/cms/cms/api_captcha.php(117): require('/Volumes/dune/w...')
#2 /Volumes/dune/www-servers/cms/cms/autotest.php(457): cl_captcha->test()
#3 {main}
[11-May-2017 17:31:25 Europe/Vienna] PHP Warning: finfo_open(): Failed to load magic database at
'(null)'. in /Volumes/dune/www-servers/phpincludes/global_rh_misc.inc.php on line 3407
[11-May-2017 17:31:25 Europe/Vienna] PHP Warning: finfo_open(): Failed to load magic database at
'(null)'. in /Volumes/dune/www-servers/phpincludes/global_rh_misc.inc.php on line 3407
[11-May-2017 17:31:25 Europe/Vienna] PHP Warning: finfo_open(): Failed to load magic database at
'(null)'. in /Volumes/dune/www-servers/phpincludes/global_rh_misc.inc.php on line 3407
------------------------------------------------------------------------
[2017-05-11 15:31:29] requinix@php.net
.apk files are ZIP archives. Without looking at the extension or the actual contents of the archive
it's impossible to tell the difference between the two.
MIME detection is not perfect. Sometimes you need to check the extension too.
------------------------------------------------------------------------
[2017-05-11 15:28:04] spam2 at rhsoft dot net
problem likely is the forked libmagic which don't get updates over ages and you can't even
rebuild from the system libmagic because different versions so "/usr/bin/php
ext/fileinfo/create_data_file.php /usr/share/misc/magic.mgc > ext/fileinfo/data_file.c"
within the build process results in a sucessful but unusable build
https://bugs.php.net/bug.php?id=67516
------------------------------------------------------------------------
[2017-05-11 15:21:06] 209721949 at qq dot com
Description:
------------
i use finfo_file to get the apk file mime type, but it always return application/zip but not
application/vnd.android
Test script:
---------------
$finfo = finfo_open(FILEINFO_MIME_TYPE); extension
$filename="xxx.apk";
echo finfo_file($finfo, $filename);
finfo_close($finfo);
Expected result:
----------------
i'm not sure if it's a bug, i just want to get the right result.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74573&edit=1