bjori                                    Mon, 14 Feb 2011 15:32:02 +0000

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

Log:
Bug#54016 (finfo_file() Cannot determine filetype in archives)

Bug: http://bugs.php.net/54016 (Assigned) finfo_file: Cannot determine filetype 
in archives
      
Changed paths:
    U   php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c
    U   php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_001.phpt
    U   php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_002.phpt
    A   
php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_stream_001.phpt
    U   
php/php-src/branches/PHP_5_3/ext/fileinfo/tests/mime_content_type_001.phpt
    A   php/php-src/branches/PHP_5_3/ext/fileinfo/tests/resources/dir.zip
    U   php/php-src/trunk/ext/fileinfo/fileinfo.c
    U   php/php-src/trunk/ext/fileinfo/tests/finfo_file_001.phpt
    U   php/php-src/trunk/ext/fileinfo/tests/finfo_file_002.phpt
    A   php/php-src/trunk/ext/fileinfo/tests/finfo_file_stream_001.phpt
    U   php/php-src/trunk/ext/fileinfo/tests/mime_content_type_001.phpt
    A   php/php-src/trunk/ext/fileinfo/tests/resources/dir.zip

Modified: php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c
===================================================================
--- php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/branches/PHP_5_3/ext/fileinfo/fileinfo.c	2011-02-14 15:32:02 UTC (rev 308327)
@@ -478,7 +478,7 @@
 			/* 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");
@@ -486,17 +486,6 @@
 				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) {
@@ -512,7 +501,14 @@
 					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;

Modified: php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_001.phpt	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_001.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -24,5 +24,5 @@
 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)

Modified: php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_002.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_002.phpt	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_002.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -18,7 +18,9 @@
 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"]=>

Added: php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_stream_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_stream_001.phpt	                        (rev 0)
+++ php/php-src/branches/PHP_5_3/ext/fileinfo/tests/finfo_file_stream_001.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -0,0 +1,26 @@
+--TEST--
+finfo_file(): Files and directories inside an stream
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+<?php if (!extension_loaded('zip')) { die("skip"); } ?>
+--FILE--
+<?php
+
+$fp = finfo_open(FILEINFO_MIME_TYPE);
+$results = array();
+
+$zip = __DIR__ . "/resources/dir.zip";
+$stream = "zip://" . __DIR__ . "/resources/dir.zip";
+$dir = $stream . "#dir/";
+$png = $stream . "#dir/test.png";
+
+var_dump(
+         finfo_file($fp, $zip),
+         finfo_file($fp, $dir),
+         finfo_file($fp, $png)
+);
+?>
+--EXPECTF--
+string(15) "application/zip"
+string(9) "directory"
+string(9) "image/png"

Modified: php/php-src/branches/PHP_5_3/ext/fileinfo/tests/mime_content_type_001.phpt
===================================================================
--- php/php-src/branches/PHP_5_3/ext/fileinfo/tests/mime_content_type_001.phpt	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/branches/PHP_5_3/ext/fileinfo/tests/mime_content_type_001.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -23,7 +23,7 @@

 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


Added: php/php-src/branches/PHP_5_3/ext/fileinfo/tests/resources/dir.zip
===================================================================
(Binary files differ)


Property changes on: php/php-src/branches/PHP_5_3/ext/fileinfo/tests/resources/dir.zip
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream

Modified: php/php-src/trunk/ext/fileinfo/fileinfo.c
===================================================================
--- php/php-src/trunk/ext/fileinfo/fileinfo.c	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/trunk/ext/fileinfo/fileinfo.c	2011-02-14 15:32:02 UTC (rev 308327)
@@ -474,7 +474,7 @@
 			/* 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 @@
 				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 @@
 					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;

Modified: php/php-src/trunk/ext/fileinfo/tests/finfo_file_001.phpt
===================================================================
--- php/php-src/trunk/ext/fileinfo/tests/finfo_file_001.phpt	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/trunk/ext/fileinfo/tests/finfo_file_001.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -24,5 +24,5 @@
 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)

Modified: php/php-src/trunk/ext/fileinfo/tests/finfo_file_002.phpt
===================================================================
--- php/php-src/trunk/ext/fileinfo/tests/finfo_file_002.phpt	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/trunk/ext/fileinfo/tests/finfo_file_002.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -18,7 +18,9 @@
 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"]=>

Added: php/php-src/trunk/ext/fileinfo/tests/finfo_file_stream_001.phpt
===================================================================
--- php/php-src/trunk/ext/fileinfo/tests/finfo_file_stream_001.phpt	                        (rev 0)
+++ php/php-src/trunk/ext/fileinfo/tests/finfo_file_stream_001.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -0,0 +1,26 @@
+--TEST--
+finfo_file(): Files and directories inside an stream
+--SKIPIF--
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+<?php if (!extension_loaded('zip')) { die("skip"); } ?>
+--FILE--
+<?php
+
+$fp = finfo_open(FILEINFO_MIME_TYPE);
+$results = array();
+
+$zip = __DIR__ . "/resources/dir.zip";
+$stream = "zip://" . __DIR__ . "/resources/dir.zip";
+$dir = $stream . "#dir/";
+$png = $stream . "#dir/test.png";
+
+var_dump(
+         finfo_file($fp, $zip),
+         finfo_file($fp, $dir),
+         finfo_file($fp, $png)
+);
+?>
+--EXPECTF--
+string(15) "application/zip"
+string(9) "directory"
+string(9) "image/png"

Modified: php/php-src/trunk/ext/fileinfo/tests/mime_content_type_001.phpt
===================================================================
--- php/php-src/trunk/ext/fileinfo/tests/mime_content_type_001.phpt	2011-02-14 15:20:37 UTC (rev 308326)
+++ php/php-src/trunk/ext/fileinfo/tests/mime_content_type_001.phpt	2011-02-14 15:32:02 UTC (rev 308327)
@@ -23,7 +23,7 @@

 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


Added: php/php-src/trunk/ext/fileinfo/tests/resources/dir.zip
===================================================================
(Binary files differ)


Property changes on: php/php-src/trunk/ext/fileinfo/tests/resources/dir.zip
___________________________________________________________________
Added: svn:mime-type
   + application/octet-stream
-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to