php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63248 ext\fileinfo\tests\bug61964.phpt fails (load multiple magic files)
Submitted: 2012-10-09 14:45 UTC Modified: 2012-10-16 09:18 UTC
From: ab@php.net Assigned: ab (profile)
Status: Closed Package: *General Issues
PHP Version: 5.4Git-2012-10-09 (Git) OS: Windows
Private report: No CVE-ID: None
 [2012-10-09 14:45 UTC] ab@php.net
Description:
------------
As one can see from the diff, there a permissions warning. Tries to set the full permissions didn't work, so I've debugged it. Here is the VS backtrace

	php_fileinfo.dll!apprentice_map(magic_set * ms, magic * * magicp, unsigned int * nmagicp, const char * fn) Line 2219	C
 	php_fileinfo.dll!apprentice_1(magic_set * ms, const char * fn, int action, mlist * mlist) Line 271	C
 	php_fileinfo.dll!file_apprentice(magic_set * ms, const char * fn, int action) Line 369	C
 	php_fileinfo.dll!magic_load(magic_set * ms, const char * magicfile) Line 308	C
 	php_fileinfo.dll!zif_finfo_open(int ht, _zval_struct * return_value, _zval_struct * * return_value_ptr, _zval_struct * this_ptr, int return_value_used, void * * * tsrm_ls) Line 345	C
 	php5ts_debug.dll!zend_do_fcall_common_helper_SPEC(_zend_execute_data * execute_data, void * * * tsrm_ls) Line 642	C
 	php5ts_debug.dll!ZEND_DO_FCALL_SPEC_CONST_HANDLER(_zend_execute_data * execute_data, void * * * tsrm_ls) Line 2236	C
 	php5ts_debug.dll!execute(_zend_op_array * op_array, void * * * tsrm_ls) Line 410	C
 	php5ts_debug.dll!zend_execute_scriapts(int type, void * * * tsrm_ls, _zval_struct * * retval, int file_count, ...) Line 1309	C
 	php5ts_debug.dll!php_execute_script(_zend_file_handle * primary_file, void * * * tsrm_ls) Line 2482	C
 	php.exe!do_cli(int argc, char * * argv, void * * * tsrm_ls) Line 988	C
 	php.exe!main(int argc, char * * argv) Line 1364	C
 	php.exe!__tmainCRTStartup() Line 582	C

The warning is produced by the finfo_open() when an existing directory is passed as a magic path.

Expected result:
----------------
Test pass

Actual result:
--------------
003+ Warning: finfo_open(C:\php-sdk\php54\vc9\x86\php-src\ext\fileinfo\tests\test-folder): failed to open stream: Permission denied in C:\php-sdk\php54\vc9\x86\php-src\ext\fileinfo\tests\bug61964.php on line 16
006- Notice: finfo_open(): Warning: offset `string' invalid in %sbug61964.php on line %d
007-
008- Notice: finfo_open(): Warning: offset ` Core' invalid in %sbug61964.php on line %d
008+ Warning: finfo_open(C:\php-sdk\php54\vc9\x86\php-src\ext\fileinfo\tests\test-folder): failed to open stream: Permission denied in C:\php-sdk\php54\vc9\x86\php-src\ext\fileinfo\tests\bug61964.php on line 30
009+ DONE: testing dir with files
010+ ===DONE===
009-
010- Notice: finfo_open(): Warning: type `Core' invalid in %sbug61964.php on line %d
011-
012- Notice: finfo_open(): Warning: offset `a' invalid in %sbug61964.php on line %d
013-
014- Notice: finfo_open(): Warning: type `a' invalid in %sbug61964.php on line %d
015-
016- Notice: finfo_open(): Warning: offset `b' invalid in %sbug61964.php on line %d
017-
018- Notice: finfo_open(): Warning: type `b' invalid in %sbug61964.php on line %d
019-
020- Warning: finfo_open(): Failed to load magic database at '%stest-folder'. in %sbug61964.php on line %d
021- DONE: testing dir with files
022- ===DONE===

Patches

bug63248.patch (last revision 2012-10-13 21:08 UTC by ab@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-10-10 17:51 UTC] ab@php.net
The following patch has been added/updated:

Patch Name: bug63248.patch
Revision:   1349891460
URL:        https://bugs.php.net/patch-display.php?bug=63248&patch=bug63248.patch&revision=1349891460
 [2012-10-10 18:02 UTC] ab@php.net
The issue is the following - when a directory is given as a magic path, libmagic looks for files inside it and tries to load all the files as magic files. Under windows there are two wrong points

- libmagic tries to get a directory handle
- libmagic uses opendir, readdir and so on which doesn't well on windows

The patch prevents libmagic from opening a directory and uses FindNextFile from the windows API to iterate dirs.

After applying this patch there are two tests failing

ext\fileinfo\tests\finfo_file_regex-win32.phpt
ext\fileinfo\tests\finfo_open_error-win32.phpt

But, the corresponding non win32 tests pass. Different behaviour of that two win32 tests seems co be caused because of the bug in this ticket, so then they could be kicked after the patch was applied.
 [2012-10-11 15:42 UTC] ab@php.net
The following patch has been added/updated:

Patch Name: bug63248.patch
Revision:   1349970121
URL:        https://bugs.php.net/patch-display.php?bug=63248&patch=bug63248.patch&revision=1349970121
 [2012-10-11 15:53 UTC] ab@php.net
Updated the patch, using the PHPs readdir implementation win32/readdir.c instead of reimlementing it :)
 [2012-10-11 22:40 UTC] mattficken@php.net
Most recent patch fixes the actual problem for me. Test still fails, but I don't get any error messages. It fails because the expected warning messages are missing.
 [2012-10-13 15:36 UTC] reeze@php.net
on windows we couldn't  fopen() or file_get_contents() a directory.
it didn't consist on *nix systems behavior

so does the test failed because of this. 

maybe we could update streams implementation?
 [2012-10-13 21:08 UTC] ab@php.net
The following patch has been added/updated:

Patch Name: bug63248.patch
Revision:   1350162505
URL:        https://bugs.php.net/patch-display.php?bug=63248&patch=bug63248.patch&revision=1350162505
 [2012-10-13 21:16 UTC] ab@php.net
@reeze, that's exactly what it's about - prevent tries to get dir handle on windows. Another part of that is that it was using dirent_a.lib to iterate a dir which doesn't work on 5.4 as expected. I've updated the patch where that part is implemented with streams. Could you try it on windows please? Was the previous patch working for you on windows?
 [2012-10-14 12:30 UTC] reeze@php.net
I didn't have build environment installed, will try that later :)
 [2012-10-15 20:27 UTC] mattficken@php.net
Using the latest patch, all fileinfo tests, including bug61964 now pass for me on Win7sp1x64.
 [2012-10-16 09:05 UTC] ab@php.net
-Summary: ext\fileinfo\tests\bug61964.phpt fails +Summary: ext\fileinfo\tests\bug61964.phpt fails (load multiple magic files)
 [2012-10-16 09:15 UTC] ab@php.net
-Status: Open +Status: Closed
 [2012-10-16 09:15 UTC] ab@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6d019deee206dd76396bcaff9497ae3619d279b0
Log: Fixed bug #63248 Load multiple magic files on win
 [2012-10-16 09:18 UTC] ab@php.net
thanks for testing guys )
 [2012-10-16 09:18 UTC] ab@php.net
-Assigned To: +Assigned To: ab
 [2014-10-07 23:21 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=6d019deee206dd76396bcaff9497ae3619d279b0
Log: Fixed bug #63248 Load multiple magic files on win
 [2014-10-07 23:32 UTC] stas@php.net
Automatic comment on behalf of ab
Revision: http://git.php.net/?p=php-src-security.git;a=commit;h=6d019deee206dd76396bcaff9497ae3619d279b0
Log: Fixed bug #63248 Load multiple magic files on win
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 05:01:29 2024 UTC