summaryrefslogtreecommitdiff
path: root/ext/fileinfo
diff options
context:
space:
mode:
authorAnatoliy Belsky <ab@php.net>2012-11-27 16:33:58 +0100
committerAnatoliy Belsky <ab@php.net>2012-11-27 16:33:58 +0100
commite6b727d3b7eef06d8b7b6a4638a95e7a571d97b5 (patch)
tree3b181a41d663f18bb03e87e629806ae670fb5d0b /ext/fileinfo
parenteff12e56b63531ca70f2bc55bbb59366b65191e0 (diff)
downloadphp-git-e6b727d3b7eef06d8b7b6a4638a95e7a571d97b5.tar.gz
Fixed bug #63590 Fileinfo delivers ifferent results in TS and NTS under Windows
Diffstat (limited to 'ext/fileinfo')
-rw-r--r--ext/fileinfo/libmagic.patch42
-rw-r--r--ext/fileinfo/libmagic/apprentice.c4
-rw-r--r--ext/fileinfo/tests/finfo_file_regex-win32.phpt36
-rw-r--r--ext/fileinfo/tests/finfo_file_regex.phpt3
-rw-r--r--ext/fileinfo/tests/finfo_open_error-win32.phpt46
-rw-r--r--ext/fileinfo/tests/finfo_open_error.phpt3
6 files changed, 27 insertions, 107 deletions
diff --git a/ext/fileinfo/libmagic.patch b/ext/fileinfo/libmagic.patch
index 9647620f1e..9be317b008 100644
--- a/ext/fileinfo/libmagic.patch
+++ b/ext/fileinfo/libmagic.patch
@@ -1,6 +1,6 @@
diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
--- libmagic.orig/apprentice.c Sat Dec 17 18:17:18 2011
-+++ libmagic/apprentice.c Fri Nov 23 13:04:15 2012
++++ libmagic/apprentice.c Tue Nov 27 16:25:57 2012
@@ -29,6 +29,8 @@
* apprentice - make one pass through /etc/magic, learning its secrets.
*/
@@ -267,11 +267,11 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
- ssize_t len;
+ size_t len;
+ size_t lineno = 0;
++
++ php_stream *stream;
- FILE *f = fopen(ms->file = fn, "r");
- if (f == NULL) {
-+ php_stream *stream;
-+
+ TSRMLS_FETCH();
+
+#if PHP_API_VERSION < 20100412
@@ -765,14 +765,18 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
if (strip) {
if ((p = strrchr(fn, '/')) != NULL)
-@@ -2370,14 +2405,14 @@
+@@ -2370,14 +2405,18 @@
q++;
/* Compatibility with old code that looked in .mime */
if (ms->flags & MAGIC_MIME) {
- asprintf(&buf, "%.*s.mime%s", (int)(q - fn), fn, ext);
- if (access(buf, R_OK) != -1) {
+ spprintf(&buf, MAXPATHLEN, "%.*s.mime%s", (int)(q - fn), fn, ext);
++#ifdef PHP_WIN32
++ if (VCWD_ACCESS(buf, R_OK) == 0) {
++#else
+ if (VCWD_ACCESS(buf, R_OK) != -1) {
++#endif
ms->flags &= MAGIC_MIME_TYPE;
return buf;
}
@@ -784,7 +788,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
/* Compatibility with old code that looked in .mime */
if (strstr(p, ".mime") != NULL)
-@@ -2467,7 +2502,7 @@
+@@ -2467,7 +2506,7 @@
m->offset = swap4((uint32_t)m->offset);
m->in_offset = swap4((uint32_t)m->in_offset);
m->lineno = swap4((uint32_t)m->lineno);
@@ -795,7 +799,7 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
}
diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c
--- libmagic.orig/ascmagic.c Sat Dec 17 18:17:18 2011
-+++ libmagic/ascmagic.c Wed Mar 28 15:35:25 2012
++++ libmagic/ascmagic.c Tue Apr 10 09:46:33 2012
@@ -139,10 +139,8 @@
/* malloc size is a conservative overestimate; could be
improved, or at least realloced after conversion. */
@@ -821,7 +825,7 @@ diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c
}
diff -u libmagic.orig/cdf.c libmagic/cdf.c
--- libmagic.orig/cdf.c Mon Feb 20 23:35:29 2012
-+++ libmagic/cdf.c Mon Apr 2 17:43:23 2012
++++ libmagic/cdf.c Tue Apr 10 09:46:33 2012
@@ -43,7 +43,17 @@
#include <err.h>
#endif
@@ -885,7 +889,7 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c
} else {
diff -u libmagic.orig/cdf.h libmagic/cdf.h
--- libmagic.orig/cdf.h Fri Feb 17 06:28:31 2012
-+++ libmagic/cdf.h Wed Mar 28 15:35:25 2012
++++ libmagic/cdf.h Tue Apr 10 09:46:34 2012
@@ -35,7 +35,7 @@
#ifndef _H_CDF_
#define _H_CDF_
@@ -923,7 +927,7 @@ diff -u libmagic.orig/cdf.h libmagic/cdf.h
void cdf_unpack_header(cdf_header_t *, char *);
diff -u libmagic.orig/cdf_time.c libmagic/cdf_time.c
--- libmagic.orig/cdf_time.c Tue Dec 13 14:48:41 2011
-+++ libmagic/cdf_time.c Wed Mar 28 15:35:25 2012
++++ libmagic/cdf_time.c Tue Apr 10 09:46:34 2012
@@ -96,7 +96,7 @@
}
@@ -982,7 +986,7 @@ diff -u libmagic.orig/cdf_time.c libmagic/cdf_time.c
char *p, *q;
diff -u libmagic.orig/compress.c libmagic/compress.c
--- libmagic.orig/compress.c Sat Dec 17 18:17:18 2011
-+++ libmagic/compress.c Mon Apr 2 17:43:23 2012
++++ libmagic/compress.c Tue Apr 10 09:46:34 2012
@@ -32,6 +32,7 @@
* uncompress(method, old, n, newch) - uncompress old into new,
* using method, return sizeof new
@@ -1145,7 +1149,7 @@ diff -u libmagic.orig/compress.c libmagic/compress.c
+#endif /* if PHP_FILEINFO_UNCOMPRESS */
diff -u libmagic.orig/file.h libmagic/file.h
--- libmagic.orig/file.h Tue Sep 20 17:30:14 2011
-+++ libmagic/file.h Sun Apr 22 20:06:21 2012
++++ libmagic/file.h Mon Apr 23 17:58:54 2012
@@ -33,11 +33,9 @@
#ifndef __file_h__
#define __file_h__
@@ -1320,7 +1324,7 @@ diff -u libmagic.orig/file.h libmagic/file.h
#endif /* __file_h__ */
diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c
--- libmagic.orig/fsmagic.c Tue Aug 23 10:57:10 2011
-+++ libmagic/fsmagic.c Wed Mar 28 15:35:26 2012
++++ libmagic/fsmagic.c Tue Apr 10 09:46:34 2012
@@ -59,27 +59,21 @@
# define minor(dev) ((dev) & 0xff)
#endif
@@ -1645,7 +1649,7 @@ diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c
/*
diff -u libmagic.orig/funcs.c libmagic/funcs.c
--- libmagic.orig/funcs.c Sat Dec 17 18:17:18 2011
-+++ libmagic/funcs.c Sun Apr 22 20:06:21 2012
++++ libmagic/funcs.c Mon Apr 23 17:58:54 2012
@@ -41,52 +41,42 @@
#if defined(HAVE_WCTYPE_H)
#include <wctype.h>
@@ -1941,7 +1945,7 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c
+
diff -u libmagic.orig/magic.c libmagic/magic.c
--- libmagic.orig/magic.c Thu May 26 03:27:59 2011
-+++ libmagic/magic.c Mon Apr 2 12:38:04 2012
++++ libmagic/magic.c Tue Apr 10 09:46:34 2012
@@ -25,11 +25,6 @@
* SUCH DAMAGE.
*/
@@ -2319,7 +2323,7 @@ diff -u libmagic.orig/magic.c libmagic/magic.c
magic_error(struct magic_set *ms)
diff -u libmagic.orig/magic.h libmagic/magic.h
--- libmagic.orig/magic.h Sun Dec 18 15:54:43 2011
-+++ libmagic/magic.h Wed Mar 28 15:35:26 2012
++++ libmagic/magic.h Tue Apr 10 09:46:34 2012
@@ -85,6 +85,7 @@
const char *magic_getpath(const char *, int);
@@ -2338,7 +2342,7 @@ diff -u libmagic.orig/magic.h libmagic/magic.h
diff -u libmagic.orig/print.c libmagic/print.c
--- libmagic.orig/print.c Tue Sep 20 17:28:09 2011
-+++ libmagic/print.c Thu Apr 5 10:22:12 2012
++++ libmagic/print.c Tue Nov 27 16:24:35 2012
@@ -29,6 +29,9 @@
* print.c - debugging printout routines
*/
@@ -2533,7 +2537,7 @@ diff -u libmagic.orig/print.c libmagic/print.c
protected const char *
diff -u libmagic.orig/readcdf.c libmagic/readcdf.c
--- libmagic.orig/readcdf.c Mon Feb 20 21:04:58 2012
-+++ libmagic/readcdf.c Wed Mar 28 15:35:26 2012
++++ libmagic/readcdf.c Tue Apr 10 09:46:34 2012
@@ -30,7 +30,11 @@
#endif
@@ -2581,7 +2585,7 @@ diff -u libmagic.orig/readcdf.c libmagic/readcdf.c
*ec = '\0';
diff -u libmagic.orig/readelf.c libmagic/readelf.c
--- libmagic.orig/readelf.c Tue Aug 23 10:57:10 2011
-+++ libmagic/readelf.c Mon Apr 2 17:43:23 2012
++++ libmagic/readelf.c Tue Apr 10 09:46:34 2012
@@ -49,7 +49,7 @@
off_t, int *, int);
private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
@@ -2738,7 +2742,7 @@ diff -u libmagic.orig/readelf.c libmagic/readelf.c
if (fstat(fd, &st) == -1) {
diff -u libmagic.orig/softmagic.c libmagic/softmagic.c
--- libmagic.orig/softmagic.c Sat Dec 17 18:17:18 2011
-+++ libmagic/softmagic.c Fri May 25 09:48:22 2012
++++ libmagic/softmagic.c Fri May 25 09:59:25 2012
@@ -41,6 +41,11 @@
#include <stdlib.h>
#include <time.h>
diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c
index ee1ad4d6e8..e88a3e6c86 100644
--- a/ext/fileinfo/libmagic/apprentice.c
+++ b/ext/fileinfo/libmagic/apprentice.c
@@ -2406,7 +2406,11 @@ mkdbname(struct magic_set *ms, const char *fn, int strip)
/* Compatibility with old code that looked in .mime */
if (ms->flags & MAGIC_MIME) {
spprintf(&buf, MAXPATHLEN, "%.*s.mime%s", (int)(q - fn), fn, ext);
+#ifdef PHP_WIN32
+ if (VCWD_ACCESS(buf, R_OK) == 0) {
+#else
if (VCWD_ACCESS(buf, R_OK) != -1) {
+#endif
ms->flags &= MAGIC_MIME_TYPE;
return buf;
}
diff --git a/ext/fileinfo/tests/finfo_file_regex-win32.phpt b/ext/fileinfo/tests/finfo_file_regex-win32.phpt
deleted file mode 100644
index 1eda48c4d0..0000000000
--- a/ext/fileinfo/tests/finfo_file_regex-win32.phpt
+++ /dev/null
@@ -1,36 +0,0 @@
---TEST--
-Test finfo_file() function : regex rules
---SKIPIF--
-<?php require_once(dirname(__FILE__) . '/skipif.inc');
-if (substr(PHP_OS, 0, 3) != 'WIN') {
- die('skip.. only for Windows');
-}
-?>
---FILE--
-<?php
-/**
- * Works with the unix file command:
- * $ file -m magic resources/test.awk
- * resources/test.awk: awk script, ASCII text
- */
-$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
-$finfo = finfo_open( FILEINFO_MIME, $magicFile );
-
-echo "*** Testing finfo_file() : regex rules ***\n";
-
-// Calling finfo_file() with all possible arguments
-$file = __DIR__ . '/resources/test.awk';
-var_dump( finfo_file( $finfo, $file ) );
-var_dump( finfo_file( $finfo, $file, FILEINFO_CONTINUE ) );
-
-// Windows uses libfileinfo 1.0.5-dev
-// this may be causing the slightly different output from the first
-// finfo_file() call
-
-?>
-===DONE===
---EXPECTF--
-*** Testing finfo_file() : regex rules ***
-string(10) "text/plain"
-string(22) "awk script, ASCII text"
-===DONE===
diff --git a/ext/fileinfo/tests/finfo_file_regex.phpt b/ext/fileinfo/tests/finfo_file_regex.phpt
index ee4c8b0b7a..7d9cd3adfa 100644
--- a/ext/fileinfo/tests/finfo_file_regex.phpt
+++ b/ext/fileinfo/tests/finfo_file_regex.phpt
@@ -2,9 +2,6 @@
Test finfo_file() function : regex rules
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc');
-if (substr(PHP_OS, 0, 3) == 'WIN') {
- die('skip.. only for Non Windows Systems');
-}
?>
--FILE--
<?php
diff --git a/ext/fileinfo/tests/finfo_open_error-win32.phpt b/ext/fileinfo/tests/finfo_open_error-win32.phpt
deleted file mode 100644
index bd50327b2d..0000000000
--- a/ext/fileinfo/tests/finfo_open_error-win32.phpt
+++ /dev/null
@@ -1,46 +0,0 @@
---TEST--
-Test finfo_open() function : error functionality
---SKIPIF--
-<?php require_once(dirname(__FILE__) . '/skipif.inc');
-if(substr(PHP_OS, 0, 3) != 'WIN' )
- die("skip Not Valid for Linux");
-?>
---FILE--
-<?php
-/* Prototype : resource finfo_open([int options [, string arg]])
- * Description: Create a new fileinfo resource.
- * Source code: ext/fileinfo/fileinfo.c
- * Alias to functions:
- */
-
-$magicFile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
-
-echo "*** Testing finfo_open() : error functionality ***\n";
-
-var_dump( finfo_open( FILEINFO_MIME, 'foobarfile' ) );
-var_dump( finfo_open( array(), $magicFile ) );
-var_dump( finfo_open( FILEINFO_MIME, $magicFile, 'extraArg' ) );
-var_dump( finfo_open( PHP_INT_MAX - 1, $magicFile ) );
-var_dump( finfo_open( 'foobar' ) );
-
-var_dump( new finfo('foobar') );
-
-?>
-===DONE===
---EXPECTF--
-*** Testing finfo_open() : error functionality ***
-bool(false)
-
-Warning: finfo_open() expects parameter 1 to be long, array given in %s on line %d
-bool(false)
-
-Warning: finfo_open() expects at most 2 parameters, 3 given in %s on line %d
-bool(false)
-resource(%d) of type (file_info)
-
-Warning: finfo_open() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
-bool(false)
-
-Warning: finfo::finfo() expects parameter 1 to be long, %unicode_string_optional% given in %s on line %d
-NULL
-===DONE===
diff --git a/ext/fileinfo/tests/finfo_open_error.phpt b/ext/fileinfo/tests/finfo_open_error.phpt
index 7bf60bfe63..b4448a27a3 100644
--- a/ext/fileinfo/tests/finfo_open_error.phpt
+++ b/ext/fileinfo/tests/finfo_open_error.phpt
@@ -2,9 +2,6 @@
Test finfo_open() function : error functionality
--SKIPIF--
<?php require_once(dirname(__FILE__) . '/skipif.inc');
-if(substr(PHP_OS, 0, 3) == 'WIN' )
- die("skip Not Valid for Windows");
-?>
--FILE--
<?php
/* Prototype : resource finfo_open([int options [, string arg]])