From: Hannes Magnusson Date: Mon, 14 Feb 2011 15:32:02 +0000 (+0000) Subject: Bug#54016 (finfo_file() Cannot determine filetype in archives) X-Git-Tag: php-5.4.0alpha1~191^2~238 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d1d61ce6120c1a84aa1e8b003159566158fa4ae1;p=php Bug#54016 (finfo_file() Cannot determine filetype in archives) --- diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index fc25f23be9..e5d28e88ce 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -474,7 +474,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime /* determine if the file is a local file or remote URL */ char *tmp2; php_stream_wrapper *wrap; - struct stat sb; + php_stream_statbuf ssb; if (buffer == NULL || !*buffer) { php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty filename or path"); @@ -482,17 +482,6 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime goto clean; } - if (php_sys_stat(buffer, &sb) == 0) { - if (sb.st_mode & _S_IFDIR) { - ret_val = mime_directory; - goto common; - } - } else { - php_error_docref(NULL TSRMLS_CC, E_WARNING, "File or path not found '%s'", buffer); - RETVAL_FALSE; - goto clean; - } - wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0 TSRMLS_CC); if (wrap) { @@ -508,7 +497,14 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime goto clean; } - ret_val = (char *)magic_stream(magic, stream); + if (php_stream_stat(stream, &ssb) == SUCCESS) { + if (ssb.sb.st_mode & S_IFDIR) { + ret_val = mime_directory; + } else { + ret_val = (char *)magic_stream(magic, stream); + } + } + php_stream_close(stream); } break; diff --git a/ext/fileinfo/tests/finfo_file_001.phpt b/ext/fileinfo/tests/finfo_file_001.phpt index 7452b5265b..263230321a 100644 --- a/ext/fileinfo/tests/finfo_file_001.phpt +++ b/ext/fileinfo/tests/finfo_file_001.phpt @@ -24,5 +24,5 @@ Warning: finfo_file(): Empty filename or path in %s on line %d bool(false) string(9) "directory" -Warning: finfo_file(): File or path not found '&' in %s on line %d +Warning: finfo_file(&): failed to open stream: No such file or directory in %s on line %d bool(false) diff --git a/ext/fileinfo/tests/finfo_file_002.phpt b/ext/fileinfo/tests/finfo_file_002.phpt index 6b8ae28ceb..9ed19a9762 100644 --- a/ext/fileinfo/tests/finfo_file_002.phpt +++ b/ext/fileinfo/tests/finfo_file_002.phpt @@ -18,7 +18,9 @@ ksort($results); var_dump($results); ?> --EXPECTF-- -array(5) { +array(6) { + ["%s/resources/dir.zip"]=> + string(15) "application/zip" ["%s/resources/test.bmp"]=> string(14) "image/x-ms-bmp" ["%s/resources/test.gif"]=> diff --git a/ext/fileinfo/tests/finfo_file_stream_001.phpt b/ext/fileinfo/tests/finfo_file_stream_001.phpt new file mode 100644 index 0000000000..5535259cd8 --- /dev/null +++ b/ext/fileinfo/tests/finfo_file_stream_001.phpt @@ -0,0 +1,26 @@ +--TEST-- +finfo_file(): Files and directories inside an stream +--SKIPIF-- + + +--FILE-- + +--EXPECTF-- +string(15) "application/zip" +string(9) "directory" +string(9) "image/png" diff --git a/ext/fileinfo/tests/mime_content_type_001.phpt b/ext/fileinfo/tests/mime_content_type_001.phpt index 5adab8f53c..72dd201007 100644 --- a/ext/fileinfo/tests/mime_content_type_001.phpt +++ b/ext/fileinfo/tests/mime_content_type_001.phpt @@ -23,7 +23,7 @@ Warning: mime_content_type(): Can only process string or stream arguments in %s Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d -Warning: mime_content_type(): File or path not found 'foo/inexistent' in %s on line %d +Warning: mime_content_type(foo/inexistent): failed to open stream: No such file or directory in %s on line %d Warning: mime_content_type(): Empty filename or path in %s on line %d diff --git a/ext/fileinfo/tests/resources/dir.zip b/ext/fileinfo/tests/resources/dir.zip new file mode 100644 index 0000000000..f133b961ed Binary files /dev/null and b/ext/fileinfo/tests/resources/dir.zip differ