summaryrefslogtreecommitdiff
path: root/ext/fileinfo
diff options
context:
space:
mode:
Diffstat (limited to 'ext/fileinfo')
-rw-r--r--ext/fileinfo/libmagic.patch124
-rw-r--r--ext/fileinfo/libmagic/softmagic.c25
-rw-r--r--ext/fileinfo/tests/finfo_file_002.phpt4
-rw-r--r--ext/fileinfo/tests/finfo_file_regex-win32.phpt36
-rw-r--r--ext/fileinfo/tests/finfo_file_regex.phpt32
-rw-r--r--ext/fileinfo/tests/finfo_open_error-win32.phpt46
-rw-r--r--ext/fileinfo/tests/finfo_open_error.phpt5
-rw-r--r--ext/fileinfo/tests/resources/test.awk1
8 files changed, 173 insertions, 100 deletions
diff --git a/ext/fileinfo/libmagic.patch b/ext/fileinfo/libmagic.patch
index baeac1dc1..48a02360b 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 2012-04-22 19:30:43.182305355 +0800
-+++ libmagic/apprentice.c 2012-04-22 19:28:57.346309536 +0800
+--- libmagic.orig/apprentice.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/apprentice.c 2012-04-22 18:57:16.215980866 +0200
@@ -29,6 +29,8 @@
* apprentice - make one pass through /etc/magic, learning its secrets.
*/
@@ -729,8 +729,8 @@ diff -u libmagic.orig/apprentice.c libmagic/apprentice.c
m->str_flags = swap4(m->str_flags);
}
diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c
---- libmagic.orig/ascmagic.c 2012-04-22 19:30:43.182305355 +0800
-+++ libmagic/ascmagic.c 2012-04-22 19:28:57.330309533 +0800
+--- libmagic.orig/ascmagic.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/ascmagic.c 2012-04-22 18:57:16.215980866 +0200
@@ -139,10 +139,8 @@
/* malloc size is a conservative overestimate; could be
improved, or at least realloced after conversion. */
@@ -755,8 +755,8 @@ diff -u libmagic.orig/ascmagic.c libmagic/ascmagic.c
return rv;
}
diff -u libmagic.orig/cdf.c libmagic/cdf.c
---- libmagic.orig/cdf.c 2012-04-22 19:30:43.182305355 +0800
-+++ libmagic/cdf.c 2012-04-22 19:28:57.370309531 +0800
+--- libmagic.orig/cdf.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/cdf.c 2012-04-22 18:57:16.219978162 +0200
@@ -43,7 +43,17 @@
#include <err.h>
#endif
@@ -819,8 +819,8 @@ diff -u libmagic.orig/cdf.c libmagic/cdf.c
(void)fprintf(stderr, "timestamp %s\n", buf);
} else {
diff -u libmagic.orig/cdf.h libmagic/cdf.h
---- libmagic.orig/cdf.h 2012-04-22 19:30:43.182305355 +0800
-+++ libmagic/cdf.h 2012-04-22 19:28:57.370309531 +0800
+--- libmagic.orig/cdf.h 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/cdf.h 2012-04-22 18:57:16.219978162 +0200
@@ -35,7 +35,7 @@
#ifndef _H_CDF_
#define _H_CDF_
@@ -857,8 +857,8 @@ diff -u libmagic.orig/cdf.h libmagic/cdf.h
void cdf_swap_header(cdf_header_t *);
void cdf_unpack_header(cdf_header_t *, char *);
diff -u libmagic.orig/cdf_time.c libmagic/cdf_time.c
---- libmagic.orig/cdf_time.c 2012-04-22 19:30:43.182305355 +0800
-+++ libmagic/cdf_time.c 2012-04-22 19:28:57.326309537 +0800
+--- libmagic.orig/cdf_time.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/cdf_time.c 2012-04-22 18:57:16.219978162 +0200
@@ -96,7 +96,7 @@
}
@@ -916,8 +916,8 @@ diff -u libmagic.orig/cdf_time.c libmagic/cdf_time.c
static const char *ref = "Sat Apr 23 01:30:00 1977";
char *p, *q;
diff -u libmagic.orig/compress.c libmagic/compress.c
---- libmagic.orig/compress.c 2012-04-22 19:30:43.182305355 +0800
-+++ libmagic/compress.c 2012-04-22 19:28:57.314309548 +0800
+--- libmagic.orig/compress.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/compress.c 2012-04-22 18:57:16.219978162 +0200
@@ -32,6 +32,7 @@
* uncompress(method, old, n, newch) - uncompress old into new,
* using method, return sizeof new
@@ -1079,8 +1079,8 @@ diff -u libmagic.orig/compress.c libmagic/compress.c
-#endif
+#endif /* if PHP_FILEINFO_UNCOMPRESS */
diff -u libmagic.orig/file.h libmagic/file.h
---- libmagic.orig/file.h 2012-04-22 19:30:43.186305188 +0800
-+++ libmagic/file.h 2012-04-22 19:49:58.922256776 +0800
+--- libmagic.orig/file.h 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/file.h 2012-04-22 18:57:16.219978162 +0200
@@ -33,11 +33,9 @@
#ifndef __file_h__
#define __file_h__
@@ -1252,8 +1252,8 @@ 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 2012-04-22 19:30:43.186305188 +0800
-+++ libmagic/fsmagic.c 2012-04-22 19:28:57.298309521 +0800
+--- libmagic.orig/fsmagic.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/fsmagic.c 2012-04-22 18:57:16.219978162 +0200
@@ -59,27 +59,21 @@
# define minor(dev) ((dev) & 0xff)
#endif
@@ -1577,8 +1577,8 @@ diff -u libmagic.orig/fsmagic.c libmagic/fsmagic.c
/*
diff -u libmagic.orig/funcs.c libmagic/funcs.c
---- libmagic.orig/funcs.c 2012-04-22 19:30:43.186305188 +0800
-+++ libmagic/funcs.c 2012-04-22 19:28:57.370309531 +0800
+--- libmagic.orig/funcs.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/funcs.c 2012-04-22 18:57:16.219978162 +0200
@@ -41,52 +41,42 @@
#if defined(HAVE_WCTYPE_H)
#include <wctype.h>
@@ -1872,11 +1872,9 @@ diff -u libmagic.orig/funcs.c libmagic/funcs.c
+ return rep_cnt;
}
+
-Only in libmagic.orig: funcs.c.orig
-Only in libmagic.orig: funcs.c.rej
diff -u libmagic.orig/magic.c libmagic/magic.c
---- libmagic.orig/magic.c 2012-04-22 19:30:43.186305188 +0800
-+++ libmagic/magic.c 2012-04-22 19:28:57.370309531 +0800
+--- libmagic.orig/magic.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/magic.c 2012-04-22 18:57:16.219978162 +0200
@@ -25,11 +25,6 @@
* SUCH DAMAGE.
*/
@@ -2253,8 +2251,8 @@ diff -u libmagic.orig/magic.c libmagic/magic.c
public const char *
magic_error(struct magic_set *ms)
diff -u libmagic.orig/magic.h libmagic/magic.h
---- libmagic.orig/magic.h 2012-04-22 19:30:43.190305058 +0800
-+++ libmagic/magic.h 2012-04-22 19:28:57.326309537 +0800
+--- libmagic.orig/magic.h 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/magic.h 2012-04-22 18:57:16.219978162 +0200
@@ -85,6 +85,7 @@
const char *magic_getpath(const char *, int);
@@ -2272,8 +2270,8 @@ diff -u libmagic.orig/magic.h libmagic/magic.h
int magic_errno(magic_t);
diff -u libmagic.orig/print.c libmagic/print.c
---- libmagic.orig/print.c 2012-04-22 19:30:43.190305058 +0800
-+++ libmagic/print.c 2012-04-22 19:28:57.326309537 +0800
+--- libmagic.orig/print.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/print.c 2012-05-29 14:34:03.770376387 +0200
@@ -29,6 +29,9 @@
* print.c - debugging printout routines
*/
@@ -2467,8 +2465,8 @@ 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 2012-04-22 19:30:43.190305058 +0800
-+++ libmagic/readcdf.c 2012-04-22 19:28:57.326309537 +0800
+--- libmagic.orig/readcdf.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/readcdf.c 2012-04-22 18:57:16.219978162 +0200
@@ -30,7 +30,11 @@
#endif
@@ -2515,8 +2513,8 @@ diff -u libmagic.orig/readcdf.c libmagic/readcdf.c
if ((ec = strchr(c, '\n')) != NULL)
*ec = '\0';
diff -u libmagic.orig/readelf.c libmagic/readelf.c
---- libmagic.orig/readelf.c 2012-04-22 19:30:43.190305058 +0800
-+++ libmagic/readelf.c 2012-04-22 19:28:57.378309534 +0800
+--- libmagic.orig/readelf.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/readelf.c 2012-04-22 18:57:16.219978162 +0200
@@ -49,7 +49,7 @@
off_t, int *, int);
private int doshn(struct magic_set *, int, int, int, off_t, int, size_t,
@@ -2672,8 +2670,8 @@ 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 2012-04-22 19:30:43.194304945 +0800
-+++ libmagic/softmagic.c 2012-04-22 19:28:57.286309597 +0800
+--- libmagic.orig/softmagic.c 2012-05-29 14:40:41.710960045 +0200
++++ libmagic/softmagic.c 2012-05-29 14:34:31.900417647 +0200
@@ -41,6 +41,11 @@
#include <stdlib.h>
#include <time.h>
@@ -2860,7 +2858,7 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c
}
}
-@@ -1669,6 +1642,65 @@
+@@ -1669,6 +1642,42 @@
return file_strncmp(a, b, len, flags);
}
@@ -2876,29 +2874,6 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c
+
+ for (i=0; i<Z_STRLEN_P(pattern); i++, j++) {
+ switch (Z_STRVAL_P(pattern)[i]) {
-+ case '?':
-+ t[j] = '.';
-+ break;
-+ case '*':
-+ t[j++] = '.';
-+ t[j] = '*';
-+ break;
-+ case '.':
-+ t[j++] = '\\';
-+ t[j] = '.';
-+ break;
-+ case '\\':
-+ t[j++] = '\\';
-+ t[j] = '\\';
-+ break;
-+ case '(':
-+ t[j++] = '\\';
-+ t[j] = '(';
-+ break;
-+ case ')':
-+ t[j++] = '\\';
-+ t[j] = ')';
-+ break;
+ case '~':
+ t[j++] = '\\';
+ t[j] = '~';
@@ -2926,7 +2901,7 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c
private int
magiccheck(struct magic_set *ms, struct magic *m)
{
-@@ -1825,67 +1857,163 @@
+@@ -1825,67 +1834,163 @@
break;
}
case FILE_REGEX: {
@@ -2937,23 +2912,7 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c
- if (ms->search.s == NULL)
- return 0;
-
-+ zval *pattern;
-+ int options = 0;
-+ pcre_cache_entry *pce;
-+ TSRMLS_FETCH();
-+
-+ MAKE_STD_ZVAL(pattern);
-+ ZVAL_STRINGL(pattern, (char *)m->value.s, m->vallen, 0);
-+
-+ options |= PCRE_MULTILINE;
-+
-+ if (m->str_flags & STRING_IGNORE_CASE) {
-+ options |= PCRE_CASELESS;
-+ }
-+
-+ convert_libmagic_pattern(pattern, options);
-+
- l = 0;
+- l = 0;
- rc = regcomp(&rx, m->value.s,
- REG_EXTENDED|REG_NEWLINE|
- ((m->str_flags & STRING_IGNORE_CASE) ? REG_ICASE : 0));
@@ -2970,6 +2929,23 @@ diff -u libmagic.orig/softmagic.c libmagic/softmagic.c
- size_t l = ms->search.s_len - 1;
- char c = ms->search.s[l];
- ((char *)(intptr_t)ms->search.s)[l] = '\0';
++ zval *pattern;
++ int options = 0;
++ pcre_cache_entry *pce;
++ TSRMLS_FETCH();
++
++ MAKE_STD_ZVAL(pattern);
++ ZVAL_STRINGL(pattern, (char *)m->value.s, m->vallen, 0);
++
++ options |= PCRE_MULTILINE;
++
++ if (m->str_flags & STRING_IGNORE_CASE) {
++ options |= PCRE_CASELESS;
++ }
++
++ convert_libmagic_pattern(pattern, options);
++
++ l = v = 0;
+#if (PHP_MAJOR_VERSION < 6)
+ if ((pce = pcre_get_compiled_regex_cache(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern) TSRMLS_CC)) == NULL) {
#else
diff --git a/ext/fileinfo/libmagic/softmagic.c b/ext/fileinfo/libmagic/softmagic.c
index 648f64169..f9c2836dd 100644
--- a/ext/fileinfo/libmagic/softmagic.c
+++ b/ext/fileinfo/libmagic/softmagic.c
@@ -1654,29 +1654,6 @@ convert_libmagic_pattern(zval *pattern, int options)
for (i=0; i<Z_STRLEN_P(pattern); i++, j++) {
switch (Z_STRVAL_P(pattern)[i]) {
- case '?':
- t[j] = '.';
- break;
- case '*':
- t[j++] = '.';
- t[j] = '*';
- break;
- case '.':
- t[j++] = '\\';
- t[j] = '.';
- break;
- case '\\':
- t[j++] = '\\';
- t[j] = '\\';
- break;
- case '(':
- t[j++] = '\\';
- t[j] = '(';
- break;
- case ')':
- t[j++] = '\\';
- t[j] = ')';
- break;
case '~':
t[j++] = '\\';
t[j] = '~';
@@ -1873,7 +1850,7 @@ magiccheck(struct magic_set *ms, struct magic *m)
convert_libmagic_pattern(pattern, options);
- l = 0;
+ l = v = 0;
#if (PHP_MAJOR_VERSION < 6)
if ((pce = pcre_get_compiled_regex_cache(Z_STRVAL_P(pattern), Z_STRLEN_P(pattern) TSRMLS_CC)) == NULL) {
#else
diff --git a/ext/fileinfo/tests/finfo_file_002.phpt b/ext/fileinfo/tests/finfo_file_002.phpt
index 9ed19a976..3593233c3 100644
--- a/ext/fileinfo/tests/finfo_file_002.phpt
+++ b/ext/fileinfo/tests/finfo_file_002.phpt
@@ -18,9 +18,11 @@ ksort($results);
var_dump($results);
?>
--EXPECTF--
-array(6) {
+array(7) {
["%s/resources/dir.zip"]=>
string(15) "application/zip"
+ ["%s/resources/test.awk"]=>
+ string(10) "text/plain"
["%s/resources/test.bmp"]=>
string(14) "image/x-ms-bmp"
["%s/resources/test.gif"]=>
diff --git a/ext/fileinfo/tests/finfo_file_regex-win32.phpt b/ext/fileinfo/tests/finfo_file_regex-win32.phpt
new file mode 100644
index 000000000..1eda48c4d
--- /dev/null
+++ b/ext/fileinfo/tests/finfo_file_regex-win32.phpt
@@ -0,0 +1,36 @@
+--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
new file mode 100644
index 000000000..ee4c8b0b7
--- /dev/null
+++ b/ext/fileinfo/tests/finfo_file_regex.phpt
@@ -0,0 +1,32 @@
+--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 Non Windows Systems');
+}
+?>
+--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 ) );
+
+?>
+===DONE===
+--EXPECTF--
+*** Testing finfo_file() : regex rules ***
+string(28) "text/plain; charset=us-ascii"
+string(22) "awk script, ASCII text"
+===DONE===
diff --git a/ext/fileinfo/tests/finfo_open_error-win32.phpt b/ext/fileinfo/tests/finfo_open_error-win32.phpt
new file mode 100644
index 000000000..bd50327b2
--- /dev/null
+++ b/ext/fileinfo/tests/finfo_open_error-win32.phpt
@@ -0,0 +1,46 @@
+--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 19ae7a601..5d1eff597 100644
--- a/ext/fileinfo/tests/finfo_open_error.phpt
+++ b/ext/fileinfo/tests/finfo_open_error.phpt
@@ -1,7 +1,10 @@
--TEST--
Test finfo_open() function : error functionality
--SKIPIF--
-<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
+<?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]])
diff --git a/ext/fileinfo/tests/resources/test.awk b/ext/fileinfo/tests/resources/test.awk
new file mode 100644
index 000000000..e000d5041
--- /dev/null
+++ b/ext/fileinfo/tests/resources/test.awk
@@ -0,0 +1 @@
+BEGIN { print "START" }