php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Return to Bug #63248
Patch bug63248.patch revision 2012-10-13 21:08 UTC by ab@php.net
revision 2012-10-11 15:42 UTC by ab@php.net
revision 2012-10-10 17:51 UTC by ab@php.net

Patch bug63248.patch for *General Issues Bug #63248

Patch version 2012-10-10 17:51 UTC

Return to Bug #63248 | Download this patch
This patch is obsolete

Obsoleted by patches:

Patch Revisions: 2012-10-13 21:08 UTC | 2012-10-11 15:42 UTC | 2012-10-10 17:51 UTC

Developer: ab@php.net

Line 1 (now 1), was 125 lines, now 107 lines
 diff --git a/ext/fileinfo/config.w32 b/ext/fileinfo/config.w32
 index 46b87b5..873a12c 100644
 --- a/ext/fileinfo/config.w32
 +++ b/ext/fileinfo/config.w32
 @@ -4,22 +4,16 @@
  ARG_ENABLE("fileinfo", "fileinfo support", "no");
  
  if (PHP_FILEINFO != 'no') {
 -	if (CHECK_HEADER_ADD_INCLUDE("dirent.h", "CFLAGS_FILEINFO") &&
 -			CHECK_LIB("dirent_a.lib", "fileinfo", PHP_FILEINFO)) { 
 -		LIBMAGIC_SOURCES=" apprentice.c apptype.c ascmagic.c \
 -				cdf.c cdf_time.c compress.c \
 -				encoding.c fsmagic.c funcs.c \
 -				is_tar.c magic.c print.c \
 -				readcdf.c readelf.c softmagic.c";
 +	LIBMAGIC_SOURCES=" apprentice.c apptype.c ascmagic.c \
 +			cdf.c cdf_time.c compress.c \
 +			encoding.c fsmagic.c funcs.c \
 +			is_tar.c magic.c print.c \
 +			readcdf.c readelf.c softmagic.c";
  
 -		if (VCVERS < 1500) {
 -			ADD_FLAG('CFLAGS', '/Zm1000');
 -		}
 +	if (VCVERS < 1500) {
 +		ADD_FLAG('CFLAGS', '/Zm1000');
 +	}
  
 -		EXTENSION('fileinfo', 'fileinfo.c', true, "/I" + configure_module_dirname + "/libmagic /I" + configure_module_dirname);
 -		ADD_SOURCES(configure_module_dirname + '\\libmagic', LIBMAGIC_SOURCES, "fileinfo");
 -	} else {
 -		WARNING("fileinfo not enabled; libraries and headers not found");
 -		PHP_FILEINFO = "no";
 -	} 
 +	EXTENSION('fileinfo', 'fileinfo.c', true, "/I" + configure_module_dirname + "/libmagic /I" + configure_module_dirname);
 +	ADD_SOURCES(configure_module_dirname + '\\libmagic', LIBMAGIC_SOURCES, "fileinfo");
  }
  diff --git a/ext/fileinfo/libmagic/apprentice.c b/ext/fileinfo/libmagic/apprentice.c
 index d11bd15..7fe85af 100644
 index d11bd15..ff14ca0 100644
  --- a/ext/fileinfo/libmagic/apprentice.c
  +++ b/ext/fileinfo/libmagic/apprentice.c
 @@ -63,9 +63,6 @@ FILE_RCSID("@(#)$File: apprentice.c,v 1.173 2011/12/08 12:38:24 rrt Exp $")
  #include <assert.h>
  #include <ctype.h>
  #include <fcntl.h>
 -#ifndef PHP_WIN32
 -#include <dirent.h>
 -#endif
  
  #define	EATAB {while (isascii((unsigned char) *l) && \
  		      isspace((unsigned char) *l))  ++l;}
 @@ -759,8 +756,10 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 @@ -759,8 +759,10 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
   	size_t files = 0, maxfiles = 0;
   	char **filearr = NULL;
   	struct stat st;
 -	DIR *dir;
 -	struct dirent *d;
 +	php_stream *dir;
 +	php_stream_dirent d;
 +
 +	TSRMLS_FETCH();
 +#ifndef PHP_WIN32
  	DIR *dir;
  	struct dirent *d;
 +#endif
   
   	ms->flags |= MAGIC_CHECK;	/* Enable checks for parsed files */
   
 @@ -776,19 +775,20 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 @@ -776,19 +778,50 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
           /* FIXME: Read file names and sort them to prevent
              non-determinism. See Debian bug #488562. */
   	if (php_sys_stat(fn, &st) == 0 && S_ISDIR(st.st_mode)) {
  -        int mflen;
  -        char mfn[MAXPATHLEN];
 -		dir = opendir(fn);
 +#ifdef PHP_WIN32
 +		HANDLE hf;
 +		WIN32_FIND_DATA wfd;
 +		char *winfn, *sl;
 +		size_t winfn_len;
 +		int suf_len;
 +#endif
  +		int mflen;
  +		char mfn[MAXPATHLEN];
  +
 +		dir = php_stream_opendir(fn, REPORT_ERRORS, NULL);
 +#ifdef PHP_WIN32
 +# define FINFO_FOUND_MAGIC_NAME wfd.cFileName
 +		winfn_len = strlen(fn);
 +		suf_len = ('\\' == fn[winfn_len-1]) ? 2 : 3;
 +		sl = ('\\' == fn[winfn_len-1]) ? "" : "\\";
 +
 +		winfn = (char *)emalloc(sizeof(char)*(winfn_len+suf_len));
 +		sprintf(winfn, "%s%s*", fn, sl);
 +		winfn[winfn_len+suf_len-1] = '\0';
 +
 +		if ((hf = FindFirstFile(winfn, &wfd)) == INVALID_HANDLE_VALUE) {
 +			errs++;
 +			goto out;
 +		}
 +
 +		while (FindNextFile(hf, &wfd)) {
 +#else
 +# define FINFO_FOUND_MAGIC_NAME d->d_name
  		dir = opendir(fn);
   		if (!dir) {
   			errs++;
   			goto out;
   		}
 -		while ((d = readdir(dir)) != NULL) {
  		while ((d = readdir(dir)) != NULL) {
  -			if ((mflen = snprintf(mfn, sizeof(mfn), "%s/%s", fn, d->d_name)) < 0) {
 +		while (php_stream_readdir(dir, &d)) {
 +			if ((mflen = snprintf(mfn, sizeof(mfn), "%s/%s", fn, d.d_name)) < 0) {
 +#endif
 +			if ((mflen = snprintf(mfn, sizeof(mfn), "%s/%s", fn, FINFO_FOUND_MAGIC_NAME)) < 0) {
   				file_oomem(ms,
  -				    strlen(fn) + strlen(d->d_name) + 2);
 +				    strlen(fn) + strlen(d.d_name) + 2);
 +				    strlen(fn) + strlen(FINFO_FOUND_MAGIC_NAME) + 2);
   				errs++;
 -				closedir(dir);
 +				php_stream_closedir(dir);
 +#ifdef PHP_WIN32
 +				efree(winfn);
 +#else
  				closedir(dir);
 +#endif
   				goto out;
   			}
   			if (stat(mfn, &st) == -1 || !S_ISREG(st.st_mode)) {
 @@ -801,14 +801,14 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 @@ -801,14 +834,22 @@ apprentice_load(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
   				if ((filearr = CAST(char **,
   				    realloc(filearr, mlen))) == NULL) {
   					file_oomem(ms, mlen);
 -					closedir(dir);
 +					php_stream_closedir(dir);
 +#ifdef PHP_WIN32
 +					efree(winfn);
 +#else
  					closedir(dir);
 +#endif
   					errs++;
   					goto out;
   				}
   			}
   			filearr[files++] = estrndup(mfn, (mflen > sizeof(mfn) - 1)? sizeof(mfn) - 1: mflen);
   		}
 -		closedir(dir);
 +		php_stream_closedir(dir);
 +#ifdef PHP_WIN32
 +		efree(winfn);
 +#else
  		closedir(dir);
 +#endif
   		qsort(filearr, files, sizeof(*filearr), cmpstrp);
   		for (i = 0; i < files; i++) {
   			load_1(ms, action, filearr[i], &errs, &marray,
 @@ -2206,6 +2206,16 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
 @@ -2206,6 +2247,14 @@ apprentice_map(struct magic_set *ms, struct magic **magicp, uint32_t *nmagicp,
   		goto internal_loaded;
   	}
   
  +#ifdef PHP_WIN32
 +	/* Don't bother on windows with php_stream_open_wrapper,
 +	return to give apprentice_load() a chance. */
  +	if (php_stream_stat_path_ex(fn, 0, &st, NULL) == SUCCESS) {
 +               if (st.sb.st_mode & S_IFDIR) {
 +                       goto error2;
 +               }
 +       }
 +		if (st.sb.st_mode & S_IFDIR) {
 +			goto error2;
 +		}
 +	}
  +#endif
  +
   	dbname = mkdbname(ms, fn, 0);
   	if (dbname == NULL)
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 23 14:02:33 2014 UTC