1 |
From 7c1a9e37cabec0ae4369ad681e39e3924fab2b5b Mon Sep 17 00:00:00 2001 |
2 |
From: Hannes Magnusson <bjori@php.net> |
3 |
Date: Mon, 14 Feb 2011 15:32:02 +0000 |
4 |
Subject: [PATCH] Bug#54016 (finfo_file() Cannot determine filetype in |
5 |
archives) |
6 |
|
7 |
--- |
8 |
ext/fileinfo/fileinfo.c | 22 ++++++++------------ |
9 |
ext/fileinfo/tests/finfo_file_001.phpt | 2 +- |
10 |
ext/fileinfo/tests/finfo_file_002.phpt | 4 ++- |
11 |
ext/fileinfo/tests/finfo_file_stream_001.phpt | 26 +++++++++++++++++++++++++ |
12 |
ext/fileinfo/tests/mime_content_type_001.phpt | 2 +- |
13 |
ext/fileinfo/tests/resources/dir.zip | Bin 0 -> 392 bytes |
14 |
6 files changed, 40 insertions(+), 16 deletions(-) |
15 |
create mode 100644 ext/fileinfo/tests/finfo_file_stream_001.phpt |
16 |
create mode 100644 ext/fileinfo/tests/resources/dir.zip |
17 |
|
18 |
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c |
19 |
index b269726..398659b 100644 |
20 |
--- a/ext/fileinfo/fileinfo.c |
21 |
+++ b/ext/fileinfo/fileinfo.c |
22 |
@@ -478,7 +478,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime |
23 |
/* determine if the file is a local file or remote URL */ |
24 |
char *tmp2; |
25 |
php_stream_wrapper *wrap; |
26 |
- struct stat sb; |
27 |
+ php_stream_statbuf ssb; |
28 |
|
29 |
if (buffer == NULL || !*buffer) { |
30 |
php_error_docref(NULL TSRMLS_CC, E_WARNING, "Empty filename or path"); |
31 |
@@ -486,17 +486,6 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime |
32 |
goto clean; |
33 |
} |
34 |
|
35 |
- if (php_sys_stat(buffer, &sb) == 0) { |
36 |
- if (sb.st_mode & _S_IFDIR) { |
37 |
- ret_val = mime_directory; |
38 |
- goto common; |
39 |
- } |
40 |
- } else { |
41 |
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "File or path not found '%s'", buffer); |
42 |
- RETVAL_FALSE; |
43 |
- goto clean; |
44 |
- } |
45 |
- |
46 |
wrap = php_stream_locate_url_wrapper(buffer, &tmp2, 0 TSRMLS_CC); |
47 |
|
48 |
if (wrap) { |
49 |
@@ -512,7 +501,14 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime |
50 |
goto clean; |
51 |
} |
52 |
|
53 |
- ret_val = (char *)magic_stream(magic, stream); |
54 |
+ if (php_stream_stat(stream, &ssb) == SUCCESS) { |
55 |
+ if (ssb.sb.st_mode & S_IFDIR) { |
56 |
+ ret_val = mime_directory; |
57 |
+ } else { |
58 |
+ ret_val = (char *)magic_stream(magic, stream); |
59 |
+ } |
60 |
+ } |
61 |
+ |
62 |
php_stream_close(stream); |
63 |
} |
64 |
break; |
65 |
diff --git a/ext/fileinfo/tests/finfo_file_001.phpt b/ext/fileinfo/tests/finfo_file_001.phpt |
66 |
index 7452b52..2632303 100644 |
67 |
--- a/ext/fileinfo/tests/finfo_file_001.phpt |
68 |
+++ b/ext/fileinfo/tests/finfo_file_001.phpt |
69 |
@@ -24,5 +24,5 @@ Warning: finfo_file(): Empty filename or path in %s on line %d |
70 |
bool(false) |
71 |
string(9) "directory" |
72 |
|
73 |
-Warning: finfo_file(): File or path not found '&' in %s on line %d |
74 |
+Warning: finfo_file(&): failed to open stream: No such file or directory in %s on line %d |
75 |
bool(false) |
76 |
diff --git a/ext/fileinfo/tests/finfo_file_002.phpt b/ext/fileinfo/tests/finfo_file_002.phpt |
77 |
index 6b8ae28..9ed19a9 100644 |
78 |
--- a/ext/fileinfo/tests/finfo_file_002.phpt |
79 |
+++ b/ext/fileinfo/tests/finfo_file_002.phpt |
80 |
@@ -18,7 +18,9 @@ ksort($results); |
81 |
var_dump($results); |
82 |
?> |
83 |
--EXPECTF-- |
84 |
-array(5) { |
85 |
+array(6) { |
86 |
+ ["%s/resources/dir.zip"]=> |
87 |
+ string(15) "application/zip" |
88 |
["%s/resources/test.bmp"]=> |
89 |
string(14) "image/x-ms-bmp" |
90 |
["%s/resources/test.gif"]=> |
91 |
diff --git a/ext/fileinfo/tests/finfo_file_stream_001.phpt b/ext/fileinfo/tests/finfo_file_stream_001.phpt |
92 |
new file mode 100644 |
93 |
index 0000000..5535259 |
94 |
--- /dev/null |
95 |
+++ b/ext/fileinfo/tests/finfo_file_stream_001.phpt |
96 |
@@ -0,0 +1,26 @@ |
97 |
+--TEST-- |
98 |
+finfo_file(): Files and directories inside an stream |
99 |
+--SKIPIF-- |
100 |
+<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?> |
101 |
+<?php if (!extension_loaded('zip')) { die("skip"); } ?> |
102 |
+--FILE-- |
103 |
+<?php |
104 |
+ |
105 |
+$fp = finfo_open(FILEINFO_MIME_TYPE); |
106 |
+$results = array(); |
107 |
+ |
108 |
+$zip = __DIR__ . "/resources/dir.zip"; |
109 |
+$stream = "zip://" . __DIR__ . "/resources/dir.zip"; |
110 |
+$dir = $stream . "#dir/"; |
111 |
+$png = $stream . "#dir/test.png"; |
112 |
+ |
113 |
+var_dump( |
114 |
+ finfo_file($fp, $zip), |
115 |
+ finfo_file($fp, $dir), |
116 |
+ finfo_file($fp, $png) |
117 |
+); |
118 |
+?> |
119 |
+--EXPECTF-- |
120 |
+string(15) "application/zip" |
121 |
+string(9) "directory" |
122 |
+string(9) "image/png" |
123 |
diff --git a/ext/fileinfo/tests/mime_content_type_001.phpt b/ext/fileinfo/tests/mime_content_type_001.phpt |
124 |
index 5adab8f..72dd201 100644 |
125 |
--- a/ext/fileinfo/tests/mime_content_type_001.phpt |
126 |
+++ b/ext/fileinfo/tests/mime_content_type_001.phpt |
127 |
@@ -23,7 +23,7 @@ Warning: mime_content_type(): Can only process string or stream arguments in %s |
128 |
|
129 |
Warning: mime_content_type(): Can only process string or stream arguments in %s on line %d |
130 |
|
131 |
-Warning: mime_content_type(): File or path not found 'foo/inexistent' in %s on line %d |
132 |
+Warning: mime_content_type(foo/inexistent): failed to open stream: No such file or directory in %s on line %d |
133 |
|
134 |
Warning: mime_content_type(): Empty filename or path in %s on line %d |
135 |
|
136 |
diff --git a/ext/fileinfo/tests/resources/dir.zip b/ext/fileinfo/tests/resources/dir.zip |
137 |
new file mode 100644 |
138 |
index 0000000000000000000000000000000000000000..f133b961ed2ce5563cc83d1dd6148643278b6077 |
139 |
GIT binary patch |
140 |
literal 392 |
141 |
zcmWIWW@h1H0D-hxKRYl3O0Y1<Fr;J_>4%1JGBDTMNBZsp;?fFk21b?_%nS@*A^@mc |
142 |
z1gM?^tou#!f}$WGFBXV-pt?&^i%awh^3vg^fJ{O&<u%WT;^$8%JxWSQc<}X00VmU? |
143 |
z9tE8PEGqmq@8@$bvEa5*>TcY^F0p&=nQhEQKWt-VoGsR=M~m278(+4V>-fOn^vO4z |
144 |
z*Jm~c@yuISr}uh}&@6@kZ$>6LW?cS~fcj8?;jJTx3GpQ>#FuDpgP4TNk1&%M7?w1G |
145 |
a0uN*o!pFEwWMu={$^?XSfb=yGhXDZm##_h$ |
146 |
|
147 |
literal 0 |
148 |
HcmV?d00001 |
149 |
|
150 |
-- |
151 |
1.7.8 |
152 |
|