--- embedaddon/php/ext/phar/phar.c 2012/02/21 23:47:59 1.1 +++ embedaddon/php/ext/phar/phar.c 2014/06/15 20:03:53 1.1.1.5 @@ -2,7 +2,7 @@ +----------------------------------------------------------------------+ | phar php single-file executable PHP extension | +----------------------------------------------------------------------+ - | Copyright (c) 2005-2012 The PHP Group | + | Copyright (c) 2005-2014 The PHP Group | +----------------------------------------------------------------------+ | This source file is subject to version 3.01 of the PHP license, | | that is bundled with this package in the file LICENSE, and is | @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar.c,v 1.1 2012/02/21 23:47:59 misho Exp $ */ +/* $Id: phar.c,v 1.1.1.5 2014/06/15 20:03:53 misho Exp $ */ #define PHAR_MAIN 1 #include "phar_internal.h" @@ -1738,32 +1738,31 @@ static int phar_open_from_fp(php_stream* fp, char *fna static int phar_analyze_path(const char *fname, const char *ext, int ext_len, int for_create TSRMLS_DC) /* {{{ */ { php_stream_statbuf ssb; - char *realpath, old, *a = (char *)(ext + ext_len); + char *realpath; + char *filename = estrndup(fname, (ext - fname) + ext_len); - old = *a; - *a = '\0'; - - if ((realpath = expand_filepath(fname, NULL TSRMLS_CC))) { + if ((realpath = expand_filepath(filename, NULL TSRMLS_CC))) { #ifdef PHP_WIN32 phar_unixify_path_separators(realpath, strlen(realpath)); #endif if (zend_hash_exists(&(PHAR_GLOBALS->phar_fname_map), realpath, strlen(realpath))) { - *a = old; efree(realpath); + efree(filename); return SUCCESS; } if (PHAR_G(manifest_cached) && zend_hash_exists(&cached_phars, realpath, strlen(realpath))) { - *a = old; efree(realpath); + efree(filename); return SUCCESS; } efree(realpath); } - if (SUCCESS == php_stream_stat_path((char *) fname, &ssb)) { - *a = old; + if (SUCCESS == php_stream_stat_path((char *) filename, &ssb)) { + efree(filename); + if (ssb.sb.st_mode & S_IFDIR) { return FAILURE; } @@ -1777,57 +1776,56 @@ static int phar_analyze_path(const char *fname, const char *slash; if (!for_create) { - *a = old; + efree(filename); return FAILURE; } - slash = (char *) strrchr(fname, '/'); - *a = old; + slash = (char *) strrchr(filename, '/'); if (slash) { - old = *slash; *slash = '\0'; } - if (SUCCESS != php_stream_stat_path((char *) fname, &ssb)) { - if (slash) { - *slash = old; - } else { - if (!(realpath = expand_filepath(fname, NULL TSRMLS_CC))) { + if (SUCCESS != php_stream_stat_path((char *) filename, &ssb)) { + if (!slash) { + if (!(realpath = expand_filepath(filename, NULL TSRMLS_CC))) { + efree(filename); return FAILURE; } #ifdef PHP_WIN32 phar_unixify_path_separators(realpath, strlen(realpath)); #endif - a = strstr(realpath, fname) + ((ext - fname) + ext_len); - *a = '\0'; + slash = strstr(realpath, filename) + ((ext - fname) + ext_len); + *slash = '\0'; slash = strrchr(realpath, '/'); if (slash) { *slash = '\0'; } else { efree(realpath); + efree(filename); return FAILURE; } if (SUCCESS != php_stream_stat_path(realpath, &ssb)) { efree(realpath); + efree(filename); return FAILURE; } efree(realpath); if (ssb.sb.st_mode & S_IFDIR) { + efree(filename); return SUCCESS; } } + efree(filename); return FAILURE; } - if (slash) { - *slash = old; - } + efree(filename); if (ssb.sb.st_mode & S_IFDIR) { return SUCCESS; @@ -2335,7 +2333,7 @@ int phar_open_executed_filename(char *alias, int alias *error = NULL; } - fname = zend_get_executed_filename(TSRMLS_C); + fname = (char*)zend_get_executed_filename(TSRMLS_C); fname_len = strlen(fname); if (phar_open_parsed_phar(fname, fname_len, alias, alias_len, 0, REPORT_ERRORS, NULL, 0 TSRMLS_CC) == SUCCESS) { @@ -2581,6 +2579,7 @@ int phar_flush(phar_archive_data *phar, char *user_stu php_serialize_data_t metadata_hash; smart_str main_metadata_str = {0}; int free_user_stub, free_fp = 1, free_ufp = 1; + int manifest_hack = 0; if (phar->is_persistent) { if (error) { @@ -2649,11 +2648,8 @@ int phar_flush(phar_archive_data *phar, char *user_stu len = -len; } user_stub = 0; -#if PHP_MAJOR_VERSION >= 6 - if (!(len = php_stream_copy_to_mem(stubfile, (void **) &user_stub, len, 0)) || !user_stub) { -#else + if (!(len = php_stream_copy_to_mem(stubfile, &user_stub, len, 0)) || !user_stub) { -#endif if (closeoldfile) { php_stream_close(oldfile); } @@ -2935,6 +2931,12 @@ int phar_flush(phar_archive_data *phar, char *user_stu manifest_len = offset + phar->alias_len + sizeof(manifest) + main_metadata_str.len; phar_set_32(manifest, manifest_len); + /* Hack - see bug #65028, add padding byte to the end of the manifest */ + if(manifest[0] == '\r' || manifest[0] == '\n') { + manifest_len++; + phar_set_32(manifest, manifest_len); + manifest_hack = 1; + } phar_set_32(manifest+4, new_manifest_count); if (has_dirs) { *(manifest + 8) = (unsigned char) (((PHAR_API_VERSION) >> 8) & 0xFF); @@ -3059,7 +3061,23 @@ int phar_flush(phar_archive_data *phar, char *user_stu return EOF; } } + /* Hack - see bug #65028, add padding byte to the end of the manifest */ + if(manifest_hack) { + if(1 != php_stream_write(newfile, manifest, 1)) { + if (closeoldfile) { + php_stream_close(oldfile); + } + php_stream_close(newfile); + + if (error) { + spprintf(error, 0, "unable to write manifest padding byte"); + } + + return EOF; + } + } + /* now copy the actual file data to the new phar */ offset = php_stream_tell(newfile); for (zend_hash_internal_pointer_reset(&phar->manifest); @@ -3340,7 +3358,7 @@ static zend_op_array *phar_compile_file(zend_file_hand return phar_orig_compile_file(file_handle, type TSRMLS_CC); } if (strstr(file_handle->filename, ".phar") && !strstr(file_handle->filename, "://")) { - if (SUCCESS == phar_open_from_filename(file_handle->filename, strlen(file_handle->filename), NULL, 0, 0, &phar, NULL TSRMLS_CC)) { + if (SUCCESS == phar_open_from_filename((char*)file_handle->filename, strlen(file_handle->filename), NULL, 0, 0, &phar, NULL TSRMLS_CC)) { if (phar->is_zip || phar->is_tar) { zend_file_handle f = *file_handle; @@ -3421,7 +3439,7 @@ int phar_zend_open(const char *filename, zend_file_han char *fname; int fname_len; - fname = zend_get_executed_filename(TSRMLS_C); + fname = (char*)zend_get_executed_filename(TSRMLS_C); fname_len = strlen(fname); if (fname_len > 7 && !strncasecmp(fname, "phar://", 7)) { @@ -3669,7 +3687,7 @@ PHP_MINFO_FUNCTION(phar) /* {{{ */ php_info_print_table_header(2, "Phar: PHP Archive support", "enabled"); php_info_print_table_row(2, "Phar EXT version", PHP_PHAR_VERSION); php_info_print_table_row(2, "Phar API version", PHP_PHAR_API_VERSION); - php_info_print_table_row(2, "SVN revision", "$Revision: 1.1 $"); + php_info_print_table_row(2, "SVN revision", "$Id: phar.c,v 1.1.1.5 2014/06/15 20:03:53 misho Exp $"); php_info_print_table_row(2, "Phar-based phar archives", "enabled"); php_info_print_table_row(2, "Tar-based phar archives", "enabled"); php_info_print_table_row(2, "ZIP-based phar archives", "enabled");