From cd011d1e9ab97f16770c7e8025406a3ca4d7c663 Mon Sep 17 00:00:00 2001 From: Steph Fox Date: Sun, 31 Aug 2008 20:54:28 +0000 Subject: [PATCH] - MFB --- ext/phar/config.w32 | 6 +- ext/phar/dirstream.c | 5 +- ext/phar/func_interceptors.c | 13 +- ext/phar/package.php | 10 +- ext/phar/package.xml | 234 +++++++++++++++++- ext/phar/phar.c | 134 +--------- ext/phar/phar_internal.h | 1 + ext/phar/phar_object.c | 89 ++++--- ext/phar/php_phar.h | 2 +- ext/phar/stream.c | 15 +- ext/phar/stream.h | 1 - ext/phar/tar.c | 8 +- .../cache_list/files/frontcontroller.phar.inc | 13 + .../files/frontcontroller10.phar.inc | 20 ++ .../files/frontcontroller11.phar.inc | 20 ++ .../files/frontcontroller12.phar.inc | 20 ++ .../files/frontcontroller13.phar.inc | 14 ++ .../files/frontcontroller14.phar.inc | 19 ++ .../files/frontcontroller16.phar.inc | 16 ++ .../files/frontcontroller17.phar.inc | 16 ++ .../files/frontcontroller18.phar.inc | 19 ++ .../files/frontcontroller19.phar.inc | 25 ++ .../files/frontcontroller2.phar.inc | 12 + .../files/frontcontroller3.phar.inc | 18 ++ .../files/frontcontroller4.phar.inc | 18 ++ .../files/frontcontroller5.phar.inc | 12 + .../files/frontcontroller6.phar.inc | 12 + .../files/frontcontroller7.phar.inc | 12 + .../files/frontcontroller8.phar.inc | 19 ++ .../files/frontcontroller9.phar.inc | 14 ++ ext/phar/tests/cache_list/files/md5.phar | Bin 0 -> 107 bytes ext/phar/tests/cache_list/files/nophar.phar | Bin 0 -> 7049 bytes .../tests/cache_list/files/nophar.phar.inc | 10 + ext/phar/tests/cache_list/files/openssl.phar | Bin 0 -> 6901 bytes .../cache_list/files/openssl.phar.pubkey | 6 + .../tests/cache_list/files/phar_oo_test.inc | 49 ++++ ext/phar/tests/cache_list/files/phar_test.inc | 78 ++++++ ext/phar/tests/cache_list/files/private.pem | 15 ++ ext/phar/tests/cache_list/files/sha1.phar | Bin 0 -> 111 bytes ext/phar/tests/cache_list/files/sha256.phar | Bin 0 -> 123 bytes ext/phar/tests/cache_list/files/sha512.phar | Bin 0 -> 155 bytes ext/phar/tests/cache_list/files/zfapp.tgz | Bin 0 -> 1725 bytes ext/phar/tests/opendir_edgecases.phpt | 5 + ext/phar/tests/phar_buildfromiterator10.phpt | 6 +- .../phar_get_supported_signatures_001.phpt | 9 +- .../phar_get_supported_signatures_001a.phpt | 9 +- .../phar_get_supported_signatures_002.phpt | 3 +- .../phar_get_supported_signatures_002a.phpt | 9 +- ext/phar/tests/phpinfo_004.phpt | 2 +- ext/phar/tests/zip/bzip2.phpt | 80 ++++++ ext/phar/tests/zip/files/bzip2.zip | Bin 0 -> 603 bytes ext/phar/util.c | 56 +++-- ext/phar/zip.c | 15 +- 53 files changed, 933 insertions(+), 236 deletions(-) create mode 100644 ext/phar/tests/cache_list/files/frontcontroller.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller10.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller11.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller12.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller13.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller14.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller16.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller17.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller18.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller19.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller2.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller3.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller4.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller5.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller6.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller7.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller8.phar.inc create mode 100644 ext/phar/tests/cache_list/files/frontcontroller9.phar.inc create mode 100644 ext/phar/tests/cache_list/files/md5.phar create mode 100644 ext/phar/tests/cache_list/files/nophar.phar create mode 100644 ext/phar/tests/cache_list/files/nophar.phar.inc create mode 100644 ext/phar/tests/cache_list/files/openssl.phar create mode 100644 ext/phar/tests/cache_list/files/openssl.phar.pubkey create mode 100644 ext/phar/tests/cache_list/files/phar_oo_test.inc create mode 100644 ext/phar/tests/cache_list/files/phar_test.inc create mode 100644 ext/phar/tests/cache_list/files/private.pem create mode 100644 ext/phar/tests/cache_list/files/sha1.phar create mode 100644 ext/phar/tests/cache_list/files/sha256.phar create mode 100644 ext/phar/tests/cache_list/files/sha512.phar create mode 100644 ext/phar/tests/cache_list/files/zfapp.tgz create mode 100644 ext/phar/tests/zip/bzip2.phpt create mode 100644 ext/phar/tests/zip/files/bzip2.zip diff --git a/ext/phar/config.w32 b/ext/phar/config.w32 index 6632180649..e5a755084e 100644 --- a/ext/phar/config.w32 +++ b/ext/phar/config.w32 @@ -29,9 +29,11 @@ if (PHP_PHAR != "no") { WARNING('Could not enable native OpenSSL support in Phar'); } } else { - /* If ext/openssl is built-in we can at least use the API directly */ - if (PHP_OPENSSL != "no" && !PHP_OPENSSL_SHARED) { + if (PHP_OPENSSL != "no" && !PHP_OPENSSL_SHARED && !PHP_PHAR_SHARED) { AC_DEFINE('PHAR_HAVE_OPENSSL', 1); + STDOUT.WriteLine(' Native OpenSSL support in Phar enabled'); + } else { + STDOUT.WriteLine(' Native OpenSSL support in Phar disabled'); } } ADD_EXTENSION_DEP('phar', 'spl', true); diff --git a/ext/phar/dirstream.c b/ext/phar/dirstream.c index e94a11a596..2e1754d6c8 100644 --- a/ext/phar/dirstream.c +++ b/ext/phar/dirstream.c @@ -569,7 +569,6 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_ int arch_len, entry_len; php_url *resource = NULL; uint host_len; - int key_type; phar_zstr key; char *str_key; uint key_len; @@ -641,7 +640,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_ } for (zend_hash_internal_pointer_reset(&phar->manifest); - HASH_KEY_NON_EXISTANT != (key_type = zend_hash_get_current_key_ex(&phar->manifest, &key, &key_len, &unused, 0, NULL)); + HASH_KEY_NON_EXISTANT != zend_hash_get_current_key_ex(&phar->manifest, &key, &key_len, &unused, 0, NULL); zend_hash_move_forward(&phar->manifest)) { PHAR_STR(key, str_key); @@ -661,7 +660,7 @@ int phar_wrapper_rmdir(php_stream_wrapper *wrapper, char *url, int options, php_ } for (zend_hash_internal_pointer_reset(&phar->virtual_dirs); - HASH_KEY_NON_EXISTANT != (key_type = zend_hash_get_current_key_ex(&phar->virtual_dirs, &key, &key_len, &unused, 0, NULL)); + HASH_KEY_NON_EXISTANT != zend_hash_get_current_key_ex(&phar->virtual_dirs, &key, &key_len, &unused, 0, NULL); zend_hash_move_forward(&phar->virtual_dirs)) { PHAR_STR(key, str_key); diff --git a/ext/phar/func_interceptors.c b/ext/phar/func_interceptors.c index 4daa1c982e..cf08cfd47c 100644 --- a/ext/phar/func_interceptors.c +++ b/ext/phar/func_interceptors.c @@ -517,7 +517,7 @@ void phar_fancy_stat(struct stat *stat_sb, int type, zval *return_value TSRMLS_D case S_IFDIR: RETURN_STRING("dir", 1); case S_IFREG: RETURN_STRING("file", 1); } - php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown file type (%d)", stat_sb->st_mode&S_IFMT); + php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Unknown file type (%u)", stat_sb->st_mode & S_IFMT); RETURN_STRING("unknown", 1); case FS_IS_W: RETURN_BOOL((stat_sb->st_mode & wmask) != 0); @@ -681,16 +681,12 @@ splitted: #endif goto statme_baby; } else { - char *save, *save2, *actual; - int save_len, save2_len, actual_len; + char *save; + int save_len; notfound: save = PHAR_G(cwd); - save2 = entry; - actual = entry[0] == '/' ? (entry + 1) : entry; save_len = PHAR_G(cwd_len); - save2_len = entry_len; - actual_len = entry[0] == '/' ? (entry_len - 1) : entry_len; /* this file is not in the current directory, use the original path */ entry = estrndup(filename, filename_length); entry_len = filename_length; @@ -702,7 +698,6 @@ notfound: PHAR_G(cwd) = save; PHAR_G(cwd_len) = save_len; efree(entry); - efree(save2); if (IS_EXISTS_CHECK(type)) { efree(arch); RETURN_TRUE; @@ -713,7 +708,6 @@ notfound: PHAR_G(cwd) = save; PHAR_G(cwd_len) = save_len; efree(entry); - efree(save2); efree(arch); if (IS_EXISTS_CHECK(type)) { RETURN_TRUE; @@ -735,7 +729,6 @@ notfound: PHAR_G(cwd) = save; PHAR_G(cwd_len) = save_len; efree(entry); - efree(save2); efree(arch); /* Error Occured */ if (!IS_EXISTS_CHECK(type)) { diff --git a/ext/phar/package.php b/ext/phar/package.php index d7d81e2e6a..53b6939050 100644 --- a/ext/phar/package.php +++ b/ext/phar/package.php @@ -8,8 +8,12 @@ BC BREAKING RELEASE * phar.extract_list and Phar::getExtractList() are removed Major feature functionality release + * phar.cache_list allows web-based phar applications to run at equal or faster than + their on-disk equivalent [Greg] * new default stub allows running of phar-based phars without phar extension [Greg/Steph] * add support for tar-based and zip-based phar archives [Greg] + * add support for OpenSSL-based true signatures [Greg] + * add support for signatures to tar-based phar archives [Greg] * add Phar::isFileFormat() [Greg] * add Phar::convertToExecutable(), Phar::convertToData() [Greg] * add Phar::compress() [Greg] @@ -41,6 +45,10 @@ Security addition Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression API refactored, conversion API refactored +Changes since 2.0.0b1: addition of phar.cache_list, many performance improvements and bugfixes + implement OpenSSL asynchronous true package signing + add support for package signing to tar-based archives + require PHP 5.2.1+ '; if (!class_exists("Phar") && !extension_loaded("Phar")) { @@ -81,7 +89,7 @@ $options = array( $package = PEAR_PackageFileManager2::importOptions(dirname(__FILE__) . '/package.xml', $options); $package->clearDeps(); -$package->setPhpDep('5.2.0'); +$package->setPhpDep('5.2.1'); $package->setPearInstallerDep('1.4.3'); $package->addPackageDepWithChannel('optional', 'bz2', 'pecl.php.net', false, false, false, false, 'bz2'); // all this false business sets the tag that allows us to have hash built diff --git a/ext/phar/package.xml b/ext/phar/package.xml index d2d3dcdfd3..e4c2fe4f31 100644 --- a/ext/phar/package.xml +++ b/ext/phar/package.xml @@ -1,5 +1,5 @@ - + phar pecl.php.net allows running of complete applications out of .phar files (like Java .jar files) @@ -42,10 +42,10 @@ a 6x speedup measured running phpMyAdmin as a phar archive. sfox@php.net yes - 2008-05-12 - + 2008-08-31 + - 2.0.0b1 + 2.0.0RC1 1.1.1 @@ -62,8 +62,12 @@ BC BREAKING RELEASE * phar.extract_list and Phar::getExtractList() are removed Major feature functionality release + * phar.cache_list allows web-based phar applications to run at equal or faster than + their on-disk equivalent [Greg] * new default stub allows running of phar-based phars without phar extension [Greg/Steph] * add support for tar-based and zip-based phar archives [Greg] + * add support for OpenSSL-based true signatures [Greg] + * add support for signatures to tar-based phar archives [Greg] * add Phar::isFileFormat() [Greg] * add Phar::convertToExecutable(), Phar::convertToData() [Greg] * add Phar::compress() [Greg] @@ -95,6 +99,10 @@ Security addition Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression API refactored, conversion API refactored +Changes since 2.0.0b1: addition of phar.cache_list, many performance improvements and bugfixes + implement OpenSSL asynchronous true package signing + add support for package signing to tar-based archives + require PHP 5.2.1+ @@ -109,7 +117,84 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -150,8 +235,12 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + @@ -200,6 +289,8 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + @@ -239,11 +330,16 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + + @@ -259,17 +355,24 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + + + + @@ -282,6 +385,7 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + @@ -299,11 +403,14 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + @@ -343,7 +450,9 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + @@ -352,6 +461,8 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + @@ -384,15 +495,21 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + + + @@ -403,6 +520,7 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + @@ -413,6 +531,8 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + @@ -435,10 +555,14 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + @@ -447,6 +571,7 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + @@ -459,6 +584,10 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + @@ -475,6 +604,7 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + @@ -511,24 +641,34 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + + + + + + + @@ -536,6 +676,7 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + @@ -552,7 +693,9 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + @@ -567,26 +710,40 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + + + + + + + + + + + + @@ -629,6 +786,9 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression + + + @@ -676,7 +836,7 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression - 5.2.0 + 5.2.1 1.4.3 @@ -706,14 +866,14 @@ Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression - 2.0.0b1 + 2.0.0RC1 1.1.1 beta beta - 2008-05-12 + 2008-08-31 PHP License @@ -724,8 +884,12 @@ BC BREAKING RELEASE * phar.extract_list and Phar::getExtractList() are removed Major feature functionality release + * phar.cache_list allows web-based phar applications to run at equal or faster than + their on-disk equivalent [Greg] * new default stub allows running of phar-based phars without phar extension [Greg/Steph] * add support for tar-based and zip-based phar archives [Greg] + * add support for OpenSSL-based true signatures [Greg] + * add support for signatures to tar-based phar archives [Greg] * add Phar::isFileFormat() [Greg] * add Phar::convertToExecutable(), Phar::convertToData() [Greg] * add Phar::compress() [Greg] @@ -757,9 +921,65 @@ Security addition Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression API refactored, conversion API refactored +Changes since 2.0.0b1: addition of phar.cache_list, many performance improvements and bugfixes + implement OpenSSL asynchronous true package signing + add support for package signing to tar-based archives + require PHP 5.2.1+ + + + 2.0.0b1 + 1.1.1 + + + beta + beta + + 2008-05-12 + PHP License + BC BREAKING RELEASE + BC breaks: + * Phar object Compression API is rewritten. Use Phar::compress() and decompress(), + Phar::compressFiles()/decompressFiles() and PharFileInfo->compress()/decompress(). + * phar.extract_list and Phar::getExtractList() are removed + +Major feature functionality release + * new default stub allows running of phar-based phars without phar extension [Greg/Steph] + * add support for tar-based and zip-based phar archives [Greg] + * add Phar::isFileFormat() [Greg] + * add Phar::convertToExecutable(), Phar::convertToData() [Greg] + * add Phar::compress() [Greg] + * rename Phar::compressAllFiles() to compressFiles(), uncompressAllFiles() to + decompressFiles() [Greg] + * conversion to compressed or to other file formats automatically copies the archive + to a new extension (i.e. ".phar" to ".phar.tar" or ".tar" to ".tar.gz") [Steph] + * add Phar::webPhar() for running a web-based application unmodified + directly from a phar archive [Greg] + * file functions (fopen-based and stat-based) can be instructed to only look for + relative paths within a phar via Phar::interceptFileFuncs() + * add PharData class to allow manipulation/creation of non-executable tar and zip archives. [Steph] + non-executable tar/zip manipulation is allowed even when phar.readonly=1 [Greg] + * paths with . and .. work (phar://blah.phar/a/../b.php => phar://blah.phar/b.php) [Greg] + * add support for mkdir()/rmdir() and support for empty directories to phar file format [Greg] + * add option to compress the entire phar file for phar/tar file format [Greg] + * implement Phar::isCompressed() returning 0, Phar::GZ or Phar::BZ2 [Greg] + * implement Phar::copy(string $from, string $to) [Greg] + * implement Phar::running(), returns path or URL to currently executed phar + * implement Phar::buildFromIterator(Iterator $it[, string $base_directory]) [Greg] + * implement Phar::buildFromDirectory(string $base_directory[, string $regex]) [Steph] + * implement Phar::mount() for mounting external paths or files to locations inside a phar [Greg] + * add Phar::delete() [Greg] + * implement Phar::unlinkArchive() [Greg] + +Security addition + * aliases are validated so that they contain no directory separators as intended + * on conversion to other formats, user-supplied aliases are validated + +Changes since 2.0.0a2: many bugfixes, removal of phar.extract_list, compression API refactored, + conversion API refactored + 2.0.0a2 diff --git a/ext/phar/phar.c b/ext/phar/phar.c index 36ec247b17..7102f23da1 100644 --- a/ext/phar/phar.c +++ b/ext/phar/phar.c @@ -2305,7 +2305,6 @@ int phar_split_fname(char *filename, int filename_len, char **arch, int *arch_le int phar_open_executed_filename(char *alias, int alias_len, char **error TSRMLS_DC) /* {{{ */ { char *fname; - long halt_offset; zval *halt_constant; php_stream *fp; int fname_len; @@ -2340,7 +2339,6 @@ int phar_open_executed_filename(char *alias, int alias_len, char **error TSRMLS_ return FAILURE; } - halt_offset = Z_LVAL(*halt_constant); FREE_ZVAL(halt_constant); #if PHP_MAJOR_VERSION < 6 @@ -2383,7 +2381,7 @@ int phar_open_executed_filename(char *alias, int alias_len, char **error TSRMLS_ /** * Validate the CRC32 of a file opened from within the phar */ -int phar_postprocess_file(php_stream_wrapper *wrapper, int options, phar_entry_data *idata, php_uint32 crc32, char **error TSRMLS_DC) /* {{{ */ +int phar_postprocess_file(phar_entry_data *idata, php_uint32 crc32, char **error, int process_zip TSRMLS_DC) /* {{{ */ { php_uint32 crc = ~0; int len = idata->internal_file->uncompressed_filesize; @@ -2394,7 +2392,7 @@ int phar_postprocess_file(php_stream_wrapper *wrapper, int options, phar_entry_d *error = NULL; } - if (entry->is_zip) { + if (entry->is_zip && process_zip > 0) { /* verify local file header */ phar_zip_file_header local; @@ -2425,6 +2423,10 @@ int phar_postprocess_file(php_stream_wrapper *wrapper, int options, phar_entry_d } } + if (process_zip == 1) { + return SUCCESS; + } + php_stream_seek(fp, idata->zero, SEEK_SET); while (len--) { @@ -2437,7 +2439,7 @@ int phar_postprocess_file(php_stream_wrapper *wrapper, int options, phar_entry_d entry->is_crc_checked = 1; return SUCCESS; } else { - php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", idata->phar->fname, entry->filename); + spprintf(error, 0, "phar error: internal corruption of phar \"%s\" (crc32 mismatch on file \"%s\")", idata->phar->fname, entry->filename); return FAILURE; } } @@ -2515,125 +2517,6 @@ char *phar_create_default_stub(const char *index_php, const char *web_index, siz } /* }}} */ -#ifndef PHAR_HAVE_OPENSSL -static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, char *key, int key_len, char **signature, int *signature_len TSRMLS_DC) /* {{{ */ -{ - zend_fcall_info fci; - zend_fcall_info_cache fcc; - zval *zdata, *zsig, *zkey, *retval_ptr, **zp[3], *openssl; - - MAKE_STD_ZVAL(zdata); - MAKE_STD_ZVAL(openssl); - ZVAL_STRINGL(openssl, is_sign ? "openssl_sign" : "openssl_verify", is_sign ? sizeof("openssl_sign")-1 : sizeof("openssl_verify")-1, 1); - MAKE_STD_ZVAL(zsig); - ZVAL_STRINGL(zsig, *signature, *signature_len, 1); - MAKE_STD_ZVAL(zkey); - ZVAL_STRINGL(zkey, key, key_len, 1); - zp[0] = &zdata; - zp[1] = &zsig; - zp[2] = &zkey; - - php_stream_rewind(fp); - Z_TYPE_P(zdata) = IS_STRING; - Z_STRLEN_P(zdata) = end; - if (end != (off_t) php_stream_copy_to_mem(fp, &(Z_STRVAL_P(zdata)), (size_t) end, 0)) { - zval_dtor(zdata); - zval_dtor(zsig); - zval_dtor(zkey); - return FAILURE; - } - -#if PHP_VERSION_ID < 50300 - if (FAILURE == zend_fcall_info_init(openssl, &fci, &fcc TSRMLS_CC)) { -#else - if (FAILURE == zend_fcall_info_init(openssl, 0, &fci, &fcc, NULL, NULL TSRMLS_CC)) { -#endif - zval_dtor(zdata); - zval_dtor(zsig); - zval_dtor(zkey); - zval_dtor(openssl); - return FAILURE; - } - - zval_dtor(openssl); - efree(openssl); - - fci.param_count = 3; - fci.params = zp; -#if PHP_VERSION_ID < 50300 - ++(zdata->refcount); - ++(zsig->refcount); - ++(zkey->refcount); -#else - Z_ADDREF_P(zdata); - - if (is_sign) { - Z_SET_ISREF_P(zsig); - } else { - Z_ADDREF_P(zsig); - } - - Z_ADDREF_P(zkey); -#endif - fci.retval_ptr_ptr = &retval_ptr; - - if (FAILURE == zend_call_function(&fci, &fcc TSRMLS_CC)) { - zval_dtor(zdata); - zval_dtor(zsig); - zval_dtor(zkey); - efree(zdata); - efree(zkey); - efree(zsig); - return FAILURE; - } -#if PHP_VERSION_ID < 50300 - --(zdata->refcount); - --(zsig->refcount); - --(zkey->refcount); -#else - Z_DELREF_P(zdata); - - if (is_sign) { - Z_UNSET_ISREF_P(zsig); - } else { - Z_DELREF_P(zsig); - } - - Z_DELREF_P(zkey); -#endif - zval_dtor(zdata); - efree(zdata); - zval_dtor(zkey); - efree(zkey); - - switch (Z_TYPE_P(retval_ptr)) { - default: - case IS_LONG: - zval_dtor(zsig); - efree(zsig); - if (1 == Z_LVAL_P(retval_ptr)) { - efree(retval_ptr); - return SUCCESS; - } - efree(retval_ptr); - return FAILURE; - case IS_BOOL: - efree(retval_ptr); - if (Z_BVAL_P(retval_ptr)) { - *signature = estrndup(Z_STRVAL_P(zsig), Z_STRLEN_P(zsig)); - *signature_len = Z_STRLEN_P(zsig); - zval_dtor(zsig); - efree(zsig); - return SUCCESS; - } - zval_dtor(zsig); - efree(zsig); - return FAILURE; - } -} -/* }}} */ -#endif /* #ifndef PHAR_HAVE_OPENSSL */ - /** * Save phar contents to disk * @@ -3302,7 +3185,6 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, } if (phar->flags & PHAR_FILE_COMPRESSED_GZ) { - php_stream_filter *filter; /* to properly compress, we have to tell zlib to add a zlib header */ zval filterparams; @@ -3326,8 +3208,6 @@ int phar_flush(phar_archive_data *phar, char *user_stub, long len, int convert, /* use the temp stream as our base */ phar->fp = newfile; } else if (phar->flags & PHAR_FILE_COMPRESSED_BZ2) { - php_stream_filter *filter; - filter = php_stream_filter_create("bzip2.compress", NULL, php_stream_is_persistent(phar->fp) TSRMLS_CC); php_stream_filter_append(&phar->fp->writefilters, filter); php_stream_copy_to_stream(newfile, phar->fp, PHP_STREAM_COPY_ALL); diff --git a/ext/phar/phar_internal.h b/ext/phar/phar_internal.h index d97dee0adb..38b1e8816e 100755 --- a/ext/phar/phar_internal.h +++ b/ext/phar/phar_internal.h @@ -576,6 +576,7 @@ void phar_object_init(TSRMLS_D); void phar_destroy_phar_data(phar_archive_data *phar TSRMLS_DC); int phar_open_entry_file(phar_archive_data *phar, phar_entry_info *entry, char **error TSRMLS_DC); +int phar_postprocess_file(phar_entry_data *idata, php_uint32 crc32, char **error, int process_zip TSRMLS_DC); int phar_open_from_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error TSRMLS_DC); int phar_open_or_create_filename(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error TSRMLS_DC); int phar_create_or_parse_filename(char *fname, int fname_len, char *alias, int alias_len, int is_data, int options, phar_archive_data** pphar, char **error TSRMLS_DC); diff --git a/ext/phar/phar_object.c b/ext/phar/phar_object.c index fe8eff2661..db82767e4f 100755 --- a/ext/phar/phar_object.c +++ b/ext/phar/phar_object.c @@ -203,7 +203,7 @@ static int phar_file_action(phar_archive_data *phar, phar_entry_info *info, char ctr.line_len = spprintf(&(ctr.line), 0, "Content-type: %s", mime_type); sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); efree(ctr.line); - ctr.line_len = spprintf(&(ctr.line), 0, "Content-length: %d", info->uncompressed_filesize); + ctr.line_len = spprintf(&(ctr.line), 0, "Content-length: %u", info->uncompressed_filesize); sapi_header_op(SAPI_HEADER_REPLACE, &ctr TSRMLS_CC); efree(ctr.line); @@ -1393,7 +1393,7 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ { zval **value; zend_uchar key_type; - zend_bool is_splfileinfo = 0, close_fp = 1; + zend_bool close_fp = 1; ulong int_key; struct _phar_t *p_obj = (struct _phar_t*) puser; uint str_key_len, base_len = p_obj->l, fname_len; @@ -1448,7 +1448,12 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ } if (key_type > 9) { /* IS_UNICODE == 10 */ +#if PHP_VERSION_ID < 60000 +/* this can never happen, but fixes a compile warning */ + spprintf(&str_key, 0, "%s", key); +#else spprintf(&str_key, 0, "%v", key); +#endif } else { PHAR_STR(key, str_key); } @@ -1505,7 +1510,6 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ } save = fname; - is_splfileinfo = 1; goto phar_spl_fileinfo; case SPL_FS_INFO: case SPL_FS_FILE: @@ -1516,7 +1520,6 @@ static int phar_build(zend_object_iterator *iter, void *puser TSRMLS_DC) /* {{{ #endif fname_len = strlen(fname); save = fname; - is_splfileinfo = 1; goto phar_spl_fileinfo; } } @@ -1577,7 +1580,12 @@ phar_spl_fileinfo: } if (key_type > 9) { /* IS_UNICODE == 10 */ +#if PHP_VERSION_ID < 60000 +/* this can never happen, but fixes a compile warning */ + spprintf(&str_key, 0, "%s", key); +#else spprintf(&str_key, 0, "%v", key); +#endif } else { PHAR_STR(key, str_key); } @@ -1986,6 +1994,7 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c char *error; const char *pcr_error; int ext_len = ext ? strlen(ext) : 0; + int oldname_len; phar_archive_data **pphar = NULL; if (!ext) { @@ -2051,12 +2060,13 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c oldpath = estrndup(phar->fname, phar->fname_len); oldname = zend_memrchr(phar->fname, '/', phar->fname_len); ++oldname; + oldname_len = strlen(oldname); - basename = estrndup(oldname, strlen(oldname)); + basename = estrndup(oldname, oldname_len); spprintf(&newname, 0, "%s.%s", strtok(basename, "."), ext); efree(basename); - basepath = estrndup(oldpath, strlen(oldpath) - strlen(oldname)); + basepath = estrndup(oldpath, (strlen(oldpath) - oldname_len)); phar->fname_len = spprintf(&newpath, 0, "%s%s", basepath, newname); phar->fname = newpath; phar->ext = newpath + phar->fname_len - strlen(ext) - 1; @@ -2986,7 +2996,7 @@ PHP_METHOD(Phar, getSignature) add_assoc_stringl(return_value, "hash_type", "OpenSSL", 7, 1); break; default: - unknown_len = spprintf(&unknown, 0, "Unknown (%d)", phar_obj->arc.archive->sig_flags); + unknown_len = spprintf(&unknown, 0, "Unknown (%u)", phar_obj->arc.archive->sig_flags); add_assoc_stringl(return_value, "hash_type", unknown, unknown_len, 0); break; } @@ -4638,7 +4648,6 @@ PHP_METHOD(PharFileInfo, compress) case PHAR_ENT_COMPRESSED_GZ: if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_GZ) { RETURN_TRUE; - return; } if ((entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) != 0) { @@ -4670,7 +4679,6 @@ PHP_METHOD(PharFileInfo, compress) case PHAR_ENT_COMPRESSED_BZ2: if (entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_BZ2) { RETURN_TRUE; - return; } if ((entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSED_GZ) != 0) { @@ -4732,7 +4740,6 @@ PHP_METHOD(PharFileInfo, decompress) if ((entry_obj->ent.entry->flags & PHAR_ENT_COMPRESSION_MASK) == 0) { RETURN_TRUE; - return; } if (PHAR_G(readonly) && !entry_obj->ent.entry->phar->is_data) { @@ -4791,36 +4798,36 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phar___construct, 0, 0, 1) ZEND_ARG_INFO(0, flags) ZEND_ARG_INFO(0, alias) ZEND_ARG_INFO(0, fileformat) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_createDS, 0, 0, 0) ZEND_ARG_INFO(0, index) ZEND_ARG_INFO(0, webindex) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_loadPhar, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, alias) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_mapPhar, 0, 0, 0) ZEND_ARG_INFO(0, alias) ZEND_ARG_INFO(0, offset) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_mount, 0, 0, 2) ZEND_ARG_INFO(0, inphar) ZEND_ARG_INFO(0, externalfile) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_mungServer, 0, 0, 1) ZEND_ARG_INFO(0, munglist) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_webPhar, 0, 0, 0) @@ -4829,17 +4836,17 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_webPhar, 0, 0, 0) ZEND_ARG_INFO(0, f404) ZEND_ARG_INFO(0, mimetypes) ZEND_ARG_INFO(0, rewrites) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_running, 0, 0, 1) ZEND_ARG_INFO(0, retphar) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_ua, 0, 0, 1) ZEND_ARG_INFO(0, archive) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() #if HAVE_SPL @@ -4847,114 +4854,114 @@ static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_build, 0, 0, 1) ZEND_ARG_INFO(0, iterator) ZEND_ARG_INFO(0, base_directory) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_conv, 0, 0, 0) ZEND_ARG_INFO(0, format) ZEND_ARG_INFO(0, compression_type) ZEND_ARG_INFO(0, file_ext) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_comps, 0, 0, 1) ZEND_ARG_INFO(0, compression_type) ZEND_ARG_INFO(0, file_ext) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_decomp, 0, 0, 0) ZEND_ARG_INFO(0, file_ext) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_comp, 0, 0, 1) ZEND_ARG_INFO(0, compression_type) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_compo, 0, 0, 0) ZEND_ARG_INFO(0, compression_type) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_copy, 0, 0, 2) ZEND_ARG_INFO(0, newfile) ZEND_ARG_INFO(0, oldfile) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_delete, 0, 0, 1) ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_fromdir, 0, 0, 1) ZEND_ARG_INFO(0, base_dir) ZEND_ARG_INFO(0, regex) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_offsetExists, 0, 0, 1) ZEND_ARG_INFO(0, entry) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_offsetSet, 0, 0, 2) ZEND_ARG_INFO(0, entry) ZEND_ARG_INFO(0, value) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_setAlias, 0, 0, 1) ZEND_ARG_INFO(0, alias) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_setMetadata, 0, 0, 1) ZEND_ARG_INFO(0, metadata) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_setSigAlgo, 0, 0, 1) ZEND_ARG_INFO(0, algorithm) ZEND_ARG_INFO(0, privatekey) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_setStub, 0, 0, 1) ZEND_ARG_INFO(0, newstub) ZEND_ARG_INFO(0, maxlen) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_emptydir, 0, 0, 0) ZEND_ARG_INFO(0, dirname) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_extract, 0, 0, 1) ZEND_ARG_INFO(0, pathto) ZEND_ARG_INFO(0, files) ZEND_ARG_INFO(0, overwrite) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_addfile, 0, 0, 1) ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, localname) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_fromstring, 0, 0, 1) ZEND_ARG_INFO(0, localname) ZEND_ARG_INFO(0, contents) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_phar_isff, 0, 0, 1) ZEND_ARG_INFO(0, fileformat) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() #endif /* HAVE_SPL */ @@ -5026,12 +5033,12 @@ zend_function_entry php_archive_methods[] = { static ZEND_BEGIN_ARG_INFO_EX(arginfo_entry___construct, 0, 0, 1) ZEND_ARG_INFO(0, filename) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() static ZEND_BEGIN_ARG_INFO_EX(arginfo_entry_chmod, 0, 0, 1) ZEND_ARG_INFO(0, perms) -ZEND_END_ARG_INFO(); +ZEND_END_ARG_INFO() zend_function_entry php_entry_methods[] = { PHP_ME(PharFileInfo, __construct, arginfo_entry___construct, ZEND_ACC_PUBLIC) diff --git a/ext/phar/php_phar.h b/ext/phar/php_phar.h index f0a34a2e01..374f7bbee1 100644 --- a/ext/phar/php_phar.h +++ b/ext/phar/php_phar.h @@ -22,7 +22,7 @@ #ifndef PHP_PHAR_H #define PHP_PHAR_H -#define PHP_PHAR_VERSION "2.0.0b2-dev" +#define PHP_PHAR_VERSION "2.0.0RC2-dev" #include "ext/standard/basic_functions.h" extern zend_module_entry phar_module_entry; diff --git a/ext/phar/stream.c b/ext/phar/stream.c index 3f2001d4bc..5ec6e2a86d 100644 --- a/ext/phar/stream.c +++ b/ext/phar/stream.c @@ -307,8 +307,9 @@ idata_error: #endif /* check length, crc32 */ - if (!idata->internal_file->is_crc_checked && phar_postprocess_file(wrapper, options, idata, idata->internal_file->crc32, &error TSRMLS_CC) != SUCCESS) { - /* already issued the error */ + if (!idata->internal_file->is_crc_checked && phar_postprocess_file(idata, idata->internal_file->crc32, &error, 2 TSRMLS_CC) != SUCCESS) { + php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, error); + efree(error); phar_entry_delref(idata TSRMLS_CC); efree(internal_file); return NULL; @@ -675,6 +676,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio { php_url *resource; char *internal_file, *error; + int internal_file_len; phar_entry_data *idata; phar_archive_data **pphar; uint host_len; @@ -700,7 +702,7 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio host_len = strlen(resource->host); phar_request_initialize(TSRMLS_C); - if (FAILURE == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), resource->host, strlen(resource->host), (void **) &pphar)) { + if (FAILURE == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), resource->host, host_len, (void **) &pphar)) { pphar = NULL; } if (PHAR_G(readonly) && (!pphar || !(*pphar)->is_data)) { @@ -711,7 +713,8 @@ static int phar_wrapper_unlink(php_stream_wrapper *wrapper, char *url, int optio /* need to copy to strip leading "/", will get touched again */ internal_file = estrdup(resource->path + 1); - if (FAILURE == phar_get_entry_data(&idata, resource->host, strlen(resource->host), internal_file, strlen(internal_file), "r", 0, &error, 1 TSRMLS_CC)) { + internal_file_len = strlen(internal_file); + if (FAILURE == phar_get_entry_data(&idata, resource->host, host_len, internal_file, internal_file_len, "r", 0, &error, 1 TSRMLS_CC)) { /* constraints of fp refcount were not met */ if (error) { php_stream_wrapper_log_error(wrapper, options TSRMLS_CC, "unlink of \"%s\" failed: %s", url, error); @@ -828,7 +831,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char host_len = strlen(resource_from->host); - if (SUCCESS != phar_get_archive(&phar, resource_from->host, strlen(resource_from->host), NULL, 0, &error TSRMLS_CC)) { + if (SUCCESS != phar_get_archive(&phar, resource_from->host, host_len, NULL, 0, &error TSRMLS_CC)) { php_url_free(resource_from); php_url_free(resource_to); php_error_docref(NULL TSRMLS_CC, E_WARNING, "phar error: cannot rename \"%s\" to \"%s\": %s", url_from, url_to, error); @@ -909,6 +912,7 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char memcpy(new_str_key, resource_to->path + 1, to_len); memcpy(new_str_key + to_len, str_key + from_len, key_len - from_len); new_str_key[new_key_len] = 0; + is_modified = 1; entry->is_modified = 1; efree(entry->filename); @@ -921,7 +925,6 @@ static int phar_wrapper_rename(php_stream_wrapper *wrapper, char *url_from, char #else zend_hash_update_current_key_ex(&phar->manifest, key_type, new_key, new_key_len, 0, HASH_UPDATE_KEY_ANYWAY, NULL); #endif - efree(new_str_key); } } diff --git a/ext/phar/stream.h b/ext/phar/stream.h index c69202bfcf..4029025cbd 100644 --- a/ext/phar/stream.h +++ b/ext/phar/stream.h @@ -20,7 +20,6 @@ /* $Id$ */ BEGIN_EXTERN_C() -int phar_postprocess_file(php_stream_wrapper *wrapper, int options, phar_entry_data *idata, php_uint32 crc32, char **error TSRMLS_DC); php_url* phar_parse_url(php_stream_wrapper *wrapper, char *filename, char *mode, int options TSRMLS_DC); void phar_entry_remove(phar_entry_data *idata, char **error TSRMLS_DC); diff --git a/ext/phar/tar.c b/ext/phar/tar.c index e5159dab92..8a0ac07a80 100644 --- a/ext/phar/tar.c +++ b/ext/phar/tar.c @@ -255,7 +255,6 @@ int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, phar_tar_number(hdr->size, sizeof(hdr->size)); if (((!old && hdr->prefix[0] == 0) || old) && strlen(hdr->name) == sizeof(".phar/signature.bin")-1 && !strncmp(hdr->name, ".phar/signature.bin", sizeof(".phar/signature.bin")-1)) { - size_t read; if (size > 511) { if (error) { spprintf(error, 4096, "phar error: tar-based phar \"%s\" has signature that is larger than 511 bytes, cannot process", fname); @@ -291,7 +290,7 @@ bail: } /* signature checked out, let's ensure this is the last file in the phar */ size = ((size+511)&~511) + 512; - if (((hdr->typeflag == 0) || (hdr->typeflag == TAR_FILE)) && size > 0) { + if (((hdr->typeflag == '\0') || (hdr->typeflag == TAR_FILE)) && size > 0) { /* this is not good enough - seek succeeds even on truncated tars */ php_stream_seek(fp, size, SEEK_CUR); if ((uint)php_stream_tell(fp) > totalsize) { @@ -370,7 +369,7 @@ bail: return FAILURE; } - entry.tar_type = ((old & (hdr->typeflag == 0))?'0':hdr->typeflag); + entry.tar_type = ((old & (hdr->typeflag == '\0')) ? TAR_FILE : hdr->typeflag); entry.offset = entry.offset_abs = pos; /* header_offset unused in tar */ entry.fp_type = PHAR_FP; entry.flags = phar_tar_number(hdr->mode, sizeof(hdr->mode)) & PHAR_ENT_PERM_MASK; @@ -424,7 +423,6 @@ bail: } if (!actual_alias && entry.filename_len == sizeof(".phar/alias.txt")-1 && !strncmp(entry.filename, ".phar/alias.txt", sizeof(".phar/alias.txt")-1)) { - size_t read; /* found explicit alias */ if (size > 511) { if (error) { @@ -473,7 +471,7 @@ bail: size = (size+511)&~511; - if (((hdr->typeflag == 0) || (hdr->typeflag == TAR_FILE)) && size > 0) { + if (((hdr->typeflag == '\0') || (hdr->typeflag == TAR_FILE)) && size > 0) { /* this is not good enough - seek succeeds even on truncated tars */ php_stream_seek(fp, size, SEEK_CUR); if ((uint)php_stream_tell(fp) > totalsize) { diff --git a/ext/phar/tests/cache_list/files/frontcontroller.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller.phar.inc new file mode 100644 index 0000000000..80d42e886b --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller.phar.inc @@ -0,0 +1,13 @@ +setStub(' diff --git a/ext/phar/tests/cache_list/files/frontcontroller10.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller10.phar.inc new file mode 100644 index 0000000000..4c139db58b --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller10.phar.inc @@ -0,0 +1,20 @@ +setStub(' diff --git a/ext/phar/tests/cache_list/files/frontcontroller11.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller11.phar.inc new file mode 100644 index 0000000000..086350800b --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller11.phar.inc @@ -0,0 +1,20 @@ +setStub(' diff --git a/ext/phar/tests/cache_list/files/frontcontroller12.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller12.phar.inc new file mode 100644 index 0000000000..ba17df37e1 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller12.phar.inc @@ -0,0 +1,20 @@ +setStub(' diff --git a/ext/phar/tests/cache_list/files/frontcontroller13.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller13.phar.inc new file mode 100644 index 0000000000..0bfef46853 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller13.phar.inc @@ -0,0 +1,14 @@ +setStub('setStub(' diff --git a/ext/phar/tests/cache_list/files/frontcontroller16.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller16.phar.inc new file mode 100644 index 0000000000..3c9986da00 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller16.phar.inc @@ -0,0 +1,16 @@ +setStub('getMessage() . "\n"); +} +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller17.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller17.phar.inc new file mode 100644 index 0000000000..85b8729f31 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller17.phar.inc @@ -0,0 +1,16 @@ +setStub('getMessage() . "\n"); +} +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller18.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller18.phar.inc new file mode 100644 index 0000000000..847a713ba3 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller18.phar.inc @@ -0,0 +1,19 @@ +setStub('getMessage() . "\n"); +} +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller19.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller19.phar.inc new file mode 100644 index 0000000000..ba84ac410a --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller19.phar.inc @@ -0,0 +1,25 @@ +'; +$a['another.php'] = ''; +$a->setStub('getMessage() . "\n"); +} +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller2.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller2.phar.inc new file mode 100644 index 0000000000..653c79691d --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller2.phar.inc @@ -0,0 +1,12 @@ +setStub(' diff --git a/ext/phar/tests/cache_list/files/frontcontroller3.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller3.phar.inc new file mode 100644 index 0000000000..2759d9ee45 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller3.phar.inc @@ -0,0 +1,18 @@ +setStub(' "a.phps"); + if (isset($b[$a])) return $b[$a]; + return $a; +} +Phar::webPhar("whatever", "/index.php", null, array(), "s"); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller4.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller4.phar.inc new file mode 100644 index 0000000000..5c6a43f954 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller4.phar.inc @@ -0,0 +1,18 @@ +setStub(' false); + if (isset($b[$a])) return $b[$a]; + return $a; +} +Phar::webPhar("whatever", "index.php", null, array(), "s"); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller5.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller5.phar.inc new file mode 100644 index 0000000000..d2d810c367 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller5.phar.inc @@ -0,0 +1,12 @@ +setStub(' "oops")); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller6.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller6.phar.inc new file mode 100644 index 0000000000..5c900eb603 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller6.phar.inc @@ -0,0 +1,12 @@ +setStub(' 100)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller7.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller7.phar.inc new file mode 100644 index 0000000000..684970263e --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller7.phar.inc @@ -0,0 +1,12 @@ +setStub(' null)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller8.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller8.phar.inc new file mode 100644 index 0000000000..1dfb654a03 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller8.phar.inc @@ -0,0 +1,19 @@ +setStub(' "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/frontcontroller9.phar.inc b/ext/phar/tests/cache_list/files/frontcontroller9.phar.inc new file mode 100644 index 0000000000..00861f6420 --- /dev/null +++ b/ext/phar/tests/cache_list/files/frontcontroller9.phar.inc @@ -0,0 +1,14 @@ +setStub(' "foo/bar", "phps" => Phar::PHP, "php" => Phar::PHPS)); +echo "oops did not run\n"; +var_dump($_ENV, $_SERVER); +__HALT_COMPILER();'); +?> diff --git a/ext/phar/tests/cache_list/files/md5.phar b/ext/phar/tests/cache_list/files/md5.phar new file mode 100644 index 0000000000000000000000000000000000000000..8ca2f84dac204f9c3a340b653909b996a78d46a3 GIT binary patch literal 107 zcmcDqFUTlRh>!Ph^a+V~_V*3&^l=T+(6m;tx8vn9U|?Wi1Y$ub4Wxj835YW?L1ZYK pr#pyVqc!=)HjqLf$jD?_cJP&kbhnpW)9+t?+8I3{33n%7CjdlE78?Kn literal 0 HcmV?d00001 diff --git a/ext/phar/tests/cache_list/files/nophar.phar b/ext/phar/tests/cache_list/files/nophar.phar new file mode 100644 index 0000000000000000000000000000000000000000..4eb3083c924aa6c5ca06071d6607ae6f5dd8c59e GIT binary patch literal 7049 zcmb_hOK%)m70w_Kq67=XiWN7lN~(+>BP;f6_ytncca0W7lVt;O;eub_RLsJlY;ne4Y)Ga2`QrmGX zw#Ej77q9j^g8{yFcl&#TqfU3Xx7$DLfj})9L^7}6 z5(Yb$Mdo_NK&TNjVwjBU$XQ%V zE-s5Y?#sN^AQdzP+eBO_gYvt39!M?cfzK0%9>Fn;RE$C7j=4jRl#g5{Os0vRKpY1n zsX(&QBdC)il2nmVJcWuHE+AJmYxclPs;Vzni2&tqQ(mRxaV*IyPtubcGL|WH>lR&^ z#0d@q&nf(n%F2XD8CbianB9BO$(NLOi$0AQykuwCgAd5j*(8w@dM2?vmis4q1HpqSQs@Hjr zsrHMR0Vnl{9fA^sq(VmeX-93-#eQsQYK>;GU8+2EwCn7_`UCblDcFl-8v7I__a+Hz zY*FLc{w!u&Btc);RuL2--==YWBcX`I=xENZVd7s&kx6r#46HIC)j;v2#R_XwbEZ?%7w@;0jsw8~~` zo_!vVi;3LQ5kky^Ynf9jT-PU(w5@ki;2}Br#W+1NXFZXw5SJXcbL*(bC#*^SmgmI1 ziTXo=EfHuio`m=-2J`;aCjk|^z@7g`P5_An?qk*RGrlnL0yD*9qAvjBsi!0h#;D#+ z!%O14U@zZbpVu#&>+9>9^z2Pb&{`GR!S2yd1#zQ76wnM*%yXY#D#$9;?sr~e;o-x_ z8)$&a^aya1h8zPXG9{h^&&UmPz65v8QA&?VijJbY;|jB~A)Sv=&iR=Q7NB1qj@oS) z0NLD!$TUt}@65K20gc5;w}(OOW>-risv#-#fPkqPfm<(H1h4%Bg#ce%A1jZWKWWJ- zH}_APr#L^lzeRM$X<4)}#Xip@S`8)_^;vDE;)Adw-B^3VOk#utyO_|~wzVxH3;3!D z!niO7SureXRuG0CaNFwidWXF>Ljw&)9FCwppwewd6v_y6v3>#sd#d~c^}gbM`9>Tyns9pi%j?Pb z8j3?qPypxB|13+gHoFdkAuAgU3v!I#f?_i;dSdh4vT|a?n4o! zgaLF-+?A`CPto zN-)vpa{$W^A3h|@;y*)P5N3-<&0Nvt)EzdXYj5=Md5scO-d$ZY~kOKemf-^Vjs z_ill<2d5<(BNSgb5oEl!j_Vo`8hv&pI}z13-h5DxCKPRY6p~m!A=eFsXiZPF8oG;l zRs1YOF=KbC*w~|lks_36**!s6)wo<*yd@?uIfbC{ob;j+vIL;o-5ba#D6lDQiJmnl zt018ko&j*B{46A=*r*@se5~VDw1no3SFw0w#KbH3*bOBfWi%mxx^VGjoWL*c>1*Z1 zL#kT?4Jxr9%Az!&JbCZhp6hRf!VDVKTI>AEW0JNEqpA5;Il(#sR7z zE1U?Pr)(#S1iZpSo9#^FFo@~uh-A?=-;$4C(aZhz1C>du`z-^Abd@%It_+;IqDC0rRHZuHA zLSmrl>%j|NQ=|w}1c3pMGh4 X^xwyS{@btqc=oSvAg-6s4xarF4<=Ud literal 0 HcmV?d00001 diff --git a/ext/phar/tests/cache_list/files/nophar.phar.inc b/ext/phar/tests/cache_list/files/nophar.phar.inc new file mode 100644 index 0000000000..36d5628762 --- /dev/null +++ b/ext/phar/tests/cache_list/files/nophar.phar.inc @@ -0,0 +1,10 @@ +setStub($p->createDefaultStub('index.php', 'web.php')); +?> \ No newline at end of file diff --git a/ext/phar/tests/cache_list/files/openssl.phar b/ext/phar/tests/cache_list/files/openssl.phar new file mode 100644 index 0000000000000000000000000000000000000000..f3864d7faacb9b6a50215f8f0b9513839ef71fd5 GIT binary patch literal 6901 zcmb_hOKcoj70nD94fHH#5F?Nn3B6b~sq)zEc6Xd);$Q3}oj8ge8@ppfdQ7Xj>UDR; z^`olVpL`@1uo;$<4H64RNU#9JH*5wL2#FCA3nVry5E2qQRoBq7m?x<~9rS#7#xI^xO9_)%7gecKC7B95lU z@kr*WsZnG%b4QVTqlkXg9Ys#Uk>u?=;kT9GKmxHdybuXQCK-D-?tC!)JeQJBb9;Ys`S`>*NZA* zE$LF_DRQK8ugF*ub95k?@!;{wSNoo`pP?AVyZHQoA}mQFRvybu2~>dMw}@nr9=mD_ zilGn@s$yL{GI&~onjVgjNPCg9e`p`@atD2^M||1f=3*(7irHJ;^nLbgZ}^uQJ~FZ1~_jq4K$MI^?G=3Hz? z?y(fdtLJ zJYOIRXa?#4WR+^y>v!EWwpaCk=9l%W*atxTrka!L}9otX&B-}MRF)gDQ9YuG? zX=WyEIv<^s^L+~}K)>AY%+JFB$i_NE`eAH4`^;)%HR=IiBoL4N0Ln0;Wa) zZvE0Ec^5kh!GO(ut#Ux(zb{!;HxGG2@2qx`=2CHGS43PUYq3&hIuK*Z^kf0+dd{l znSwA`E^kdTt(=9NyI|==iBM8@q99H}~sj z7uTNaZc)b=kJ}Gw&u~~A&=bXrlIq;s6jq|19uhcq~jzva@KN>bMr)k~V=VP794!HC0vC&Qc526;V_= zNyC;xp&$odT8I8V*ok`RaDU=5zS4ui^qH4Fu5$?*)p-UUK66}kph;f?DUb=K?n(0fT zaG(HIlok?xEJJj(ydfpPSqJsIIaS`5yUrW=*lXY&OLm#iz{Nw;(pdb ztEWk?Ig9yI-uc+HekF`QpWkWLf-Ik{5)*;!!hKbUAfLkapE4 z77`tr)w<1KK%aC6Yin(*wYh_B{nD*F!1gDN0U-+vbzmp58U{5t&y(^rPVnWlW0`OE31p7uE1d(7?x=s`)LkNV zMg(IKqrgU~s?nCnZ30V8Y}6>e3jQfe`s7%4BC2hC z`Jf(6DB5r+B=NpUu9p;|H5}1u=q~0I@v{)cj9n>WV}}w(icq3?_XMG=ak;d3N=#sK z3PIyJ=|v%A2|%^GCy-H4U{l%>J!?o-K|(D&0N`@@K}b%qQ9soAn8l}P3C$;Nh2o15 z6QAHi+n0Eh(S!i%!o`8MY&*T>mscr@|sKg6V7FiQT1llBhT^bA=#R^7UtrKtd zart)==X}l5_YvtgDxy%TAJ0X6`*QZvejwe{#!*7}F3*Ho;mzsGUTZYgFcdJNo8PHn zm7|2NAGIy>E%bZ>2_0QcVy3FUaeykw3MYc+3R_760k5!_XDj{C_d>clB3ZP}r=;nx zCK_c*U1K0pX8<3mF{@3{XoCJ>Orb*4!KzZN5B!A#*I~%ET5GH8jn=izjV=7SWg8@R zWqIw)nKLio=hNah{lA^qp&Rl;f~Nw2f_COp_@TI}Gx#R|A{IaR#p)XU{^48i{rQ)q z0RMX4XJ3Ec{P3?&SN1;F`l!r4@rAD(z5mg-mfrowTKmbX)*nBpz5KVNa&_aw>Sx~g z&nL^b->p1+Y59%oFRi?~5#0aI2mktebJqHU|HAKoYyai*xA~vmn|k@3pI=`4@hh*# z2mko)PiJ5I+2h}BJpR$#D>IkB{r#_h^XZeh-~8(C)1S2eIrqIMwHN>WU+32kzXmT} L!_UpD8(04aZkIp_ literal 0 HcmV?d00001 diff --git a/ext/phar/tests/cache_list/files/openssl.phar.pubkey b/ext/phar/tests/cache_list/files/openssl.phar.pubkey new file mode 100644 index 0000000000..7dd79ac2bf --- /dev/null +++ b/ext/phar/tests/cache_list/files/openssl.phar.pubkey @@ -0,0 +1,6 @@ +-----BEGIN PUBLIC KEY----- +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDA3ADUiKZIEhekYShzPCZ3LFbg +rDuV44jH94OdJQfqaCQBvZXqMoG1bWOeYfbc3iO0gHWW3SKB27Sf1ZBnc5c1+YzB +mx9bFipOX2W2ouKS2YoHeIoR9leDNu4yqwBsuggFPGVPxM9ikEI+YAOGVTCd4mV5 +agpkVsHLNJWbz/nPVwIDAQAB +-----END PUBLIC KEY----- diff --git a/ext/phar/tests/cache_list/files/phar_oo_test.inc b/ext/phar/tests/cache_list/files/phar_oo_test.inc new file mode 100644 index 0000000000..9863e8da93 --- /dev/null +++ b/ext/phar/tests/cache_list/files/phar_oo_test.inc @@ -0,0 +1,49 @@ +'; + +$files = array(); + +if (!isset($pharconfig)) $pharconfig = 0; + +switch($pharconfig) +{ + default: + case 0: + $files['a.php'] = ''; + $files['b.php'] = ''; + $files['b/c.php'] = ''; + $files['b/d.php'] = ''; + $files['e.php'] = ''; + break; + case 1: + $files['a.csv'] =<< \ No newline at end of file diff --git a/ext/phar/tests/cache_list/files/phar_test.inc b/ext/phar/tests/cache_list/files/phar_test.inc new file mode 100644 index 0000000000..f82471d13b --- /dev/null +++ b/ext/phar/tests/cache_list/files/phar_test.inc @@ -0,0 +1,78 @@ + $cont) +{ + global $gflags, $files; + + $comp = NULL; + $crc32= NULL; + $clen = NULL; + $ulen = NULL; + $time = isset($ftime) ? $ftime : @mktime(12, 0, 0, 3, 1, 2006); + $flags= 0; + $perm = 0x000001B6; + $meta = NULL; + + // overwrite if array + if (is_array($cont)) + { + foreach(array('comp','crc32','clen','ulen','time','flags','perm','meta','cont') as $what) + { + if (isset($cont[$what])) + { + $$what = $cont[$what]; + } + } + } + + // create if not yet done + if (empty($comp)) $comp = $cont; + if (empty($ulen)) $ulen = strlen($cont); + if (empty($clen)) $clen = strlen($comp); + if (empty($crc32))$crc32= crc32((binary)$cont); + if (isset($meta)) $meta = serialize($meta); + + // write manifest entry + $manifest .= pack('V', strlen($name)) . (binary)$name; + $manifest .= pack('VVVVVV', $ulen, $time, $clen, $crc32, $flags|$perm, strlen($meta)) . (binary)$meta; + + // globals + $gflags |= $flags; + $files[$name] = $comp; +} + +if (!isset($alias)) $alias = 'hio'; + +if (isset($pmeta)) $pmeta = serialize($pmeta); else $pmeta = ''; + +$manifest = pack('VnVV', count($files), isset($hasdir) ? 0x1110 : 0x1000, $gflags, strlen($alias)) . (binary)$alias . pack('V', strlen($pmeta)) . (binary)$pmeta . $manifest; +$file = (binary)$file; +$file .= pack('V', strlen($manifest)) . $manifest; + +foreach($files as $cont) +{ + $file .= (binary)$cont; +} + +file_put_contents($fname, $file); + +if (@$gzip) { + $fp = gzopen($fname, 'w'); + fwrite($fp, $file); + fclose($fp); +} + +if (@$bz2) { + $fp = bzopen($fname, 'w'); + fwrite($fp, $file); + fclose($fp); +} + +?> \ No newline at end of file diff --git a/ext/phar/tests/cache_list/files/private.pem b/ext/phar/tests/cache_list/files/private.pem new file mode 100644 index 0000000000..e4f4883eb2 --- /dev/null +++ b/ext/phar/tests/cache_list/files/private.pem @@ -0,0 +1,15 @@ +-----BEGIN RSA PRIVATE KEY----- +MIICXQIBAAKBgQDA3ADUiKZIEhekYShzPCZ3LFbgrDuV44jH94OdJQfqaCQBvZXq +MoG1bWOeYfbc3iO0gHWW3SKB27Sf1ZBnc5c1+YzBmx9bFipOX2W2ouKS2YoHeIoR +9leDNu4yqwBsuggFPGVPxM9ikEI+YAOGVTCd4mV5agpkVsHLNJWbz/nPVwIDAQAB +AoGAGiS4qBbuE48ATXQuO5DH1hfYnxQ575Oskw7mdIL0k74SQ3ojvF+kXae6fVni +UQZ76JgRWKYZa2kRDymwLZXpxVbiGL9dDvQY8ZENDtWOy9s7TDtxNixbZloKBopg +J7G1B05LgetR3dgFnQOwt+e3kOu72RpS7thyBaUm8zHCRSECQQDw+h5uxE7i9CC8 +KHyJlwGoR28KZgrSpo74yWhQ+b1lzxQ+rk2wToFD/p+WNe/nf78YUl/cq0LngCKH +Y7t228VLAkEAzOHzAjuDlGGzK6Kpe67iKgXd+GpKwPr9iaFfmzABOkRwQug4LCN7 +skmzCX5pzxqMZW1xNICjeDjWsMA3d4EypQJBAJyXPA1onYaXc2oxuPPD3/zVJpAQ +TTojp8Z9Qr9T+kJdNV+h7rQB37gqjtOSiynY9nm8lbSUya4bstRd96S+HU8CQQCp +yBAd6H2oZ7IXVeuHACyRUF1ab5LVCukxtVXJ/2T1CSPSfieWhC0MWMCR/HzoUALK +RoBKVtOgW9GllRQh5yG1AkARVYbvj0XBy6XUpe5WZsLNWwpw1JreRsygcPXYh8bs +nxhCdHNHJQ01lRDMjvNLtI8a5YjJE/IeW76T2mPCiJZI +-----END RSA PRIVATE KEY----- diff --git a/ext/phar/tests/cache_list/files/sha1.phar b/ext/phar/tests/cache_list/files/sha1.phar new file mode 100644 index 0000000000000000000000000000000000000000..c7e9e7e6a2269e65cef3064a8e8a88a5766772c3 GIT binary patch literal 111 zcmcDqFUTlRh>!Ph^a+V~_V*3&^l=T+(6m;tx8vn9U|?Wi1Y$ub4Wxj835YW?L1ZYK ur#pyVqc!=)HjqLf$jDr{QLEH*-?O@t$1iIKzrC4RFUOe-QswUC>jVJG))^uI literal 0 HcmV?d00001 diff --git a/ext/phar/tests/cache_list/files/sha256.phar b/ext/phar/tests/cache_list/files/sha256.phar new file mode 100644 index 0000000000000000000000000000000000000000..81459eef0fddc53a3da951346b3a77cf1d35aa08 GIT binary patch literal 123 zcmcDqFUTlRh>!Ph^a+V~_V*3&^l=T+(6m;tx8vn9U|?Wi1Y$ub4Wxj835YW?L1ZYK zr#pyVqc!=)HjqLf$jE&1xHRa5`@T52I?1;)86O@^j$J;hdfFp?=0grwtOd{CVg{;m Ick*=t06qmD8UO$Q literal 0 HcmV?d00001 diff --git a/ext/phar/tests/cache_list/files/sha512.phar b/ext/phar/tests/cache_list/files/sha512.phar new file mode 100644 index 0000000000000000000000000000000000000000..a7473819aa8c4eb2b1c5615cafa6f067a27f7400 GIT binary patch literal 155 zcmcDqFUTlRh>!Ph^a+V~_V*3&^l=T+(6m;tx8vn9U|?Wi1Y$ub4Wxj835YW?L1ZYK zr#pyVqc!=)HjqLf$jF>!G-s`e_U_ZW-fg~mKl8xTqmzDaIAbTIxc`sjr{#$|-`$qK rIs4{buT`hE_torcY}v~ot2n3O!!+g0%ZnDRiTyo~1!#)9ldls1ZiO_U literal 0 HcmV?d00001 diff --git a/ext/phar/tests/cache_list/files/zfapp.tgz b/ext/phar/tests/cache_list/files/zfapp.tgz new file mode 100644 index 0000000000000000000000000000000000000000..fcaec86d659d3056af8e6012cf4b0fcbb924de73 GIT binary patch literal 1725 zcmV;u215BCiwFRKr>92%1MOP>Z`wE%@2|~Y@rot^(;$Sex0Z6(V@$2owTLm@?lcLd zi6PlSlCz!CYTf^S&rTQ=Xc=uuZ+HGkEy1y$pZ$4xUrfv}^jyp2Zs6-XTS5uZsMX{r zV)0X68`#5W7_~~JzEd*FrFvrrYTHt19ueav1=yiM!0+p~?*2~-bB=$T49&>nPi_aB z^IxeM6~%uVSjGQ1u!+Z>&I~r^zuIWj75`~q75|qmnLHu=58=OFD=Gfdz}@^ai@G6y z3Om@G|9YjO;(sbw&p)9wppUYG&G~Os8|wK_1wYEa{9g~ULI!JfzOH03;pYmWWb8Q9cDPW z;<^}p0G4A?M)=`}{@cPY8PJ6o?sAW`I>M--YmP`$k6W~+9?zsTF9Q1-KX;ps(Q5u0 zIw26t3E%~HTvlkw?(l01`x___yU8x@5OPV6F<}fP=l8Lfw!7O5TYZPXFz~!!;`$?y zPZR`}6;Vp;{iYtuZc8&Ia-@{xu5Y`;1JQu$CTce2Vq4m#{I7rhUEd~Gsr&z`%KuZr zkMb}7Z^{4H%a!l^m#Yow|I0Py|I@(F;s3Ye{?Et+{z7L8Z>c#ZlYoAKE)6~ti{BXz zc8>}A?^l4GJ$tWtL1#{R*<}|qpZv^$wtH#PfgO#*X=DgZoR8)4j_~1+cHxi0-Os;6 zypYi6s{f3#^8abzZvKa^$Dfb?va0`5!7BcR7p0h|J`MX1;=fck6#r>p9sjaKYJYFQ z3^3eyjy3sTxl)?tf5^Sa|HP4i%KuV;OkOlifB8~_m$1M#6hPFhiCrWW>&!a9@=V6W zIPv$J8F43|^70Z*2Q5mp>zYPIu13iq@GSyak#Xs>IrJk-7@sh#?1839kxP1DHix5_ z%+?08_CY*W`>JVxkc$v_iE6tHOnDa^)3-gs0H!w)1vr`+e!MVt>$cQ@f$Iau9hhIU zV`8I8T_%e7Aq~bbcA5M#CjgeV2^By+blkv1Elg#dz@E;k%g->nK&4<9`PNLac#*lh z?C~}3k9ZMl4TsaLb1)*jD^kl`R^A%K3#VDkG^c~u#O0O)xnyvm#W8Qr&qt&1H}K{jP2l4LR`{ zihe6Z&+qGkG?76~&xj7;uJOymFDNm;+-^=DzLoo6F52(`*e(k_^E%m{5UY?^a1n8^ z13$}!@%kgOc27_=dPN>F++3Ud;3DTAC`s%3^?mz(rLB}bJ^DI?@AgWrEE0-2VkzIW zZ|T-c|23?O|0m+yXS?ygR4-R&=RbHY;yGg z#l8^6W!RA+o8|J)FHyVwa;y(>Y z{)-MbEen0xcIH?Y|BX`hcKvUZD@Ikt|1{7e6Y6r(@v#~sfVFhe(2Fpu-}_X|eP%bV z72J&6;mzl8bQAic8;i003z+^Q7^(#PCr0f5r&Mldjy2D}Q7Si`~K=^pit`sY1t$QFyb z=Uz~gUf*$FzvspDl|x30Q|B?GzQ6u>OYwSIek5D)p71D~t90bLUd&ZKhfAf16tlmN z3Y_?8OgNQD=I6%9i=t1A3hk+pwkp&n}AM4h<%q=_v@y4NZ@c{DC~Pae~OR z;er5 --EXPECTF-- -array(33) { +array(35) { ["phar_ctx_001.phpt"]=> string(%d) "%sphar_ctx_001.phpt" ["phar_get_supported_signatures_001.phpt"]=> @@ -97,5 +97,9 @@ array(33) { string(%d) "%szip%ccorrupt_007.phpt" ["zip/corrupt_008.phpt"]=> string(%d) "%szip%ccorrupt_008.phpt" + ["zip/corrupt_009.phpt"]=> + string(%d) "%szip%ccorrupt_009.phpt" + ["zip/corrupt_010.phpt"]=> + string(%d) "%szip%ccorrupt_010.phpt" } ===DONE=== diff --git a/ext/phar/tests/phar_get_supported_signatures_001.phpt b/ext/phar/tests/phar_get_supported_signatures_001.phpt index 794da6a942..64874f66e0 100644 --- a/ext/phar/tests/phar_get_supported_signatures_001.phpt +++ b/ext/phar/tests/phar_get_supported_signatures_001.phpt @@ -1,9 +1,12 @@ --TEST-- Phar::getSupportedSignatures() --SKIPIF-- - - - + --INI-- phar.require_hash=0 phar.readonly=0 diff --git a/ext/phar/tests/phar_get_supported_signatures_001a.phpt b/ext/phar/tests/phar_get_supported_signatures_001a.phpt index f267b48141..ad929df262 100644 --- a/ext/phar/tests/phar_get_supported_signatures_001a.phpt +++ b/ext/phar/tests/phar_get_supported_signatures_001a.phpt @@ -1,9 +1,12 @@ --TEST-- Phar::getSupportedSignatures() --SKIPIF-- - - - + --INI-- phar.require_hash=0 phar.readonly=0 diff --git a/ext/phar/tests/phar_get_supported_signatures_002.phpt b/ext/phar/tests/phar_get_supported_signatures_002.phpt index fa9d02e584..d7cd350115 100644 --- a/ext/phar/tests/phar_get_supported_signatures_002.phpt +++ b/ext/phar/tests/phar_get_supported_signatures_002.phpt @@ -4,9 +4,8 @@ Phar::getSupportedSignatures() --INI-- phar.require_hash=0 diff --git a/ext/phar/tests/phar_get_supported_signatures_002a.phpt b/ext/phar/tests/phar_get_supported_signatures_002a.phpt index e4782e7ca0..ce907ff638 100644 --- a/ext/phar/tests/phar_get_supported_signatures_002a.phpt +++ b/ext/phar/tests/phar_get_supported_signatures_002a.phpt @@ -1,9 +1,12 @@ --TEST-- Phar::getSupportedSignatures() --SKIPIF-- - - - + --INI-- phar.require_hash=0 phar.readonly=0 diff --git a/ext/phar/tests/phpinfo_004.phpt b/ext/phar/tests/phpinfo_004.phpt index fd9f21882e..1ef795d5bf 100644 --- a/ext/phar/tests/phpinfo_004.phpt +++ b/ext/phar/tests/phpinfo_004.phpt @@ -6,7 +6,7 @@ if (!extension_loaded("phar")) die("skip"); if (!extension_loaded("zlib")) die("skip zlib not loaded"); if (!extension_loaded("bz2")) die("skip bz2 not loaded"); $arr = Phar::getSupportedSignatures(); -if (in_array("OpenSSL", $arr)) die("skip native openssl support enabled"); +if (in_array("OpenSSL", $arr)) die("skip openssl support enabled"); ?> --INI-- phar.readonly=0 diff --git a/ext/phar/tests/zip/bzip2.phpt b/ext/phar/tests/zip/bzip2.phpt new file mode 100644 index 0000000000..f34f1859cd --- /dev/null +++ b/ext/phar/tests/zip/bzip2.phpt @@ -0,0 +1,80 @@ +--TEST-- +Phar: process bzip2-compressed zip entry +--SKIPIF-- + + + +--FILE-- + $file) { + echo $file->getContent(); + } +} catch (Exception $e) { + echo $e->getMessage() . "\n"; +} +?> +===DONE=== +--EXPECT-- +addFile('hi', null, 'hii'); +$a->addFile('hi2', null, 'hii2', null, null, 'encrypt', 'encrypt'); +$a->writeZip(dirname(__FILE__) . '/encrypted.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii'); +$a->addFile('', null, 'stdin'); +$a->writeZip(dirname(__FILE__) . '/stdin.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hii', null, 'hii', null, null, 'filename_len', 'filename_len'); +$a->addFile('hi', null, 'hii'); +$a->writeZip(dirname(__FILE__) . '/truncfilename.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress'); +$a->writeZip(dirname(__FILE__) . '/compress_unsup1.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 2); +$a->writeZip(dirname(__FILE__) . '/compress_unsup2.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 3); +$a->writeZip(dirname(__FILE__) . '/compress_unsup3.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 4); +$a->writeZip(dirname(__FILE__) . '/compress_unsup4.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 5); +$a->writeZip(dirname(__FILE__) . '/compress_unsup5.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 6); +$a->writeZip(dirname(__FILE__) . '/compress_unsup6.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 7); +$a->writeZip(dirname(__FILE__) . '/compress_unsup7.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 9); +$a->writeZip(dirname(__FILE__) . '/compress_unsup9.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 10); +$a->writeZip(dirname(__FILE__) . '/compress_unsup10.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 14); +$a->writeZip(dirname(__FILE__) . '/compress_unsup14.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 18); +$a->writeZip(dirname(__FILE__) . '/compress_unsup18.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 19); +$a->writeZip(dirname(__FILE__) . '/compress_unsup19.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 97); +$a->writeZip(dirname(__FILE__) . '/compress_unsup97.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 98); +$a->writeZip(dirname(__FILE__) . '/compress_unsup98.zip'); +$a = new corrupt_zipmaker; +$a->addFile('hi', null, 'hii', null, null, 'compress', 'compress', 11); +$a->writeZip(dirname(__FILE__) . '/compress_unsupunknown.zip'); +?> +===DONE=== diff --git a/ext/phar/tests/zip/files/bzip2.zip b/ext/phar/tests/zip/files/bzip2.zip new file mode 100644 index 0000000000000000000000000000000000000000..2f27f027f5c5f54fad8c35131ab946e9870ea1d8 GIT binary patch literal 603 zcmWIWW@gc2U|`^3a1)wrvGlb{(^5tTh7xWD1_1^chUEOBqSAsABfWx*0=>+<|a5FHnykKTv025A88D@r#k!rz_JHtMHV_wK1czQ|a+eYeBK{>(TDXJ3hpEjhwLHX2_}Zhv{WKRhq`N8#nZyuaSx3=Df*I}WXJ zE#tZqcHi$x%y!|uH@Yqg8cuaK3O4z{$RH`a!}E9nx1NX7l(~0IZb+&+v86H2)VX?D z^?0?hs@}hlyu~^5XITdBl+<|Y_RA{9{mgn%InBzc*Ou>-U$t&#q?OsqyXw=no!XLg zexGm3S&8ID+1bzCUix-?IIEuAdRC&%u+!}1xv%zn_hs$$Iv6?i&D1MlXCGBvdb{C) z+TWwau76#xFPC__X3fmv$IhF=Vk4wjuCSf&Ycia*d!JbvrV@ISF9MIJgiJ&itoBfy)H rNsbv;gi8S90RomZf@sX>XN5#RTGR)4v$BEIGXh~4kbVzLLJSN5x6kl7 literal 0 HcmV?d00001 diff --git a/ext/phar/util.c b/ext/phar/util.c index 008bd3f5ea..0723cd2508 100644 --- a/ext/phar/util.c +++ b/ext/phar/util.c @@ -254,7 +254,7 @@ char *phar_find_in_include_path(char *filename, int filename_len, phar_archive_d { #if PHP_VERSION_ID >= 50300 char *path, *fname, *arch, *entry, *ret, *test; - int arch_len, entry_len, fname_len; + int arch_len, entry_len, fname_len, ret_len; phar_archive_data *phar; if (pphar) { @@ -322,9 +322,6 @@ splitted: efree(path); if (ret && strlen(ret) > 8 && !strncmp(ret, "phar://", 7)) { - char *arch; - int arch_len, ret_len; - ret_len = strlen(ret); /* found phar:// */ @@ -475,7 +472,7 @@ not_stream: wrapper = php_stream_locate_url_wrapper(trypath, &actual, STREAM_OPEN_FOR_INCLUDE TSRMLS_CC); if (wrapper == &php_plain_files_wrapper) { - strncpy(trypath, actual, MAXPATHLEN); + strlcpy(trypath, actual, sizeof(trypath)); } else if (!wrapper) { /* if wrapper is NULL, there was a mal-formed include_path stream wrapper, so skip this ptr */ continue; @@ -542,7 +539,7 @@ not_stream: if (wrapper == &php_plain_files_wrapper) { /* this should never technically happen, but we'll leave it here for completeness */ - strncpy(trypath, actual, MAXPATHLEN); + strlcpy(trypath, actual, sizeof(trypath)); } else if (!wrapper) { /* if wrapper is NULL, there was a malformed include_path stream wrapper this also should be impossible */ @@ -686,7 +683,7 @@ really_get_entry: if (entry->link) { efree(entry->link); entry->link = NULL; - entry->tar_type = (entry->tar_type ? TAR_FILE : 0); + entry->tar_type = (entry->is_tar ? TAR_FILE : '\0'); } if (for_write) { @@ -740,7 +737,7 @@ phar_entry_data *phar_get_or_create_entry_data(char *fname, int fname_len, char phar_unixify_path_separators(path, path_len); #endif - is_dir = (path_len > 0 && path != NULL) ? path[path_len - 1] == '/' : 0; + is_dir = (path_len && path[path_len - 1] == '/') ? 1 : 0; if (FAILURE == phar_get_archive(&phar, fname, fname_len, NULL, 0, error TSRMLS_CC)) { return NULL; @@ -877,7 +874,7 @@ int phar_copy_entry_fp(phar_entry_info *source, phar_entry_info *dest, char **er if (dest->link) { efree(dest->link); dest->link = NULL; - dest->tar_type = (dest->tar_type ? TAR_FILE : 0); + dest->tar_type = (dest->is_tar ? TAR_FILE : '\0'); } dest->fp_type = PHAR_MOD; @@ -913,6 +910,7 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS char *filtername; off_t loc; php_stream *ufp; + phar_entry_data dummy; if (follow_links && entry->link) { phar_entry_info *link_entry = phar_get_link_source(entry TSRMLS_CC); @@ -921,6 +919,10 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS } } + if (entry->is_modified) { + return SUCCESS; + } + if (entry->fp_type == PHAR_TMP) { if (!entry->fp) { entry->fp = php_stream_open_wrapper(entry->tmp, "rb", STREAM_MUST_SEEK|0, NULL); @@ -941,6 +943,13 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS } if ((entry->old_flags && !(entry->old_flags & PHAR_ENT_COMPRESSION_MASK)) || !(entry->flags & PHAR_ENT_COMPRESSION_MASK)) { + dummy.internal_file = entry; + dummy.phar = phar; + dummy.zero = entry->offset; + dummy.fp = phar_get_pharfp(phar TSRMLS_CC); + if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 1 TSRMLS_CC)) { + return FAILURE; + } return SUCCESS; } @@ -952,6 +961,14 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS } } + dummy.internal_file = entry; + dummy.phar = phar; + dummy.zero = entry->offset; + dummy.fp = phar_get_pharfp(phar TSRMLS_CC); + if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 1 TSRMLS_CC)) { + return FAILURE; + } + ufp = phar_get_entrypufp(entry TSRMLS_CC); if ((filtername = phar_decompress_filter(entry, 0)) != NULL) { @@ -991,6 +1008,11 @@ int phar_open_entry_fp(phar_entry_info *entry, char **error, int follow_links TS /* this is now the new location of the file contents within this fp */ phar_set_fp_type(entry, PHAR_UFP, loc TSRMLS_CC); + dummy.zero = entry->offset; + dummy.fp = ufp; + if (FAILURE == phar_postprocess_file(&dummy, entry->crc32, error, 0 TSRMLS_CC)) { + return FAILURE; + } return SUCCESS; } /* }}} */ @@ -1057,7 +1079,7 @@ int phar_create_writeable_entry(phar_archive_data *phar, phar_entry_info *entry, if (entry->link) { efree(entry->link); entry->link = NULL; - entry->tar_type = (entry->tar_type ? TAR_FILE : 0); + entry->tar_type = (entry->is_tar ? TAR_FILE : '\0'); } entry->fp = php_stream_fopen_tmpfile(); @@ -1114,7 +1136,7 @@ int phar_separate_entry_fp(phar_entry_info *entry, char **error TSRMLS_DC) /* {{ if (entry->link) { efree(entry->link); entry->link = NULL; - entry->tar_type = (entry->tar_type ? TAR_FILE : 0); + entry->tar_type = (entry->is_tar ? TAR_FILE : '\0'); } entry->offset = 0; @@ -1434,7 +1456,7 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in phar_unixify_path_separators(path, path_len); #endif - is_dir = path_len && (path[path_len - 1] == '/'); + is_dir = (path_len && (path[path_len - 1] == '/')) ? 1 : 0; if (error) { *error = NULL; @@ -1525,7 +1547,6 @@ phar_entry_info *phar_get_entry_info_dir(phar_archive_data *phar, char *path, in } else { char *test; int test_len; - phar_entry_info *entry; php_stream_statbuf ssb; if (SUCCESS != zend_hash_find(&phar->manifest, str_key, keylen, (void **) &entry)) { @@ -1638,6 +1659,7 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, zval_dtor(zkey); return FAILURE; } + #if PHP_VERSION_ID < 50300 if (FAILURE == zend_fcall_info_init(openssl, &fci, &fcc TSRMLS_CC)) { #else @@ -1655,7 +1677,9 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, fci.params = zp; #if PHP_VERSION_ID < 50300 ++(zdata->refcount); - ++(zsig->refcount); + if (!is_sign) { + ++(zsig->refcount); + } ++(zkey->refcount); #else Z_ADDREF_P(zdata); @@ -1684,7 +1708,9 @@ static int phar_call_openssl_signverify(int is_sign, php_stream *fp, off_t end, efree(openssl); #if PHP_VERSION_ID < 50300 --(zdata->refcount); - --(zsig->refcount); + if (!is_sign) { + --(zsig->refcount); + } --(zkey->refcount); #else Z_DELREF_P(zdata); diff --git a/ext/phar/zip.c b/ext/phar/zip.c index 07725875f4..26d873239f 100644 --- a/ext/phar/zip.c +++ b/ext/phar/zip.c @@ -159,7 +159,6 @@ int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, phar_zip_dir_end locator; char buf[sizeof(locator) + 65536]; long size; - size_t read; php_uint16 i; phar_archive_data *mydata = NULL; phar_entry_info entry = {0}; @@ -181,7 +180,7 @@ int phar_parse_zipfile(php_stream *fp, char *fname, int fname_len, char *alias, php_stream_seek(fp, 0, SEEK_SET); } - if (!(read = php_stream_read(fp, buf, size))) { + if (!php_stream_read(fp, buf, size)) { php_stream_close(fp); if (error) { spprintf(error, 4096, "phar error: unable to read in data to search for end of central directory in zip-based phar \"%s\"", fname); @@ -491,7 +490,6 @@ foundit: php_stream_filter_remove(filter, 1 TSRMLS_CC); } else if (entry.flags & PHAR_ENT_COMPRESSED_BZ2) { - php_stream_filter *filter; filter = php_stream_filter_create("bzip2.decompress", NULL, php_stream_is_persistent(fp) TSRMLS_CC); if (!filter) { @@ -655,6 +653,7 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */ struct _phar_zip_pass *p; php_uint32 newcrc32; off_t offset; + int not_really_modified = 0; entry = (phar_entry_info *)data; p = (struct _phar_zip_pass*) arg; @@ -723,6 +722,12 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */ return ZEND_HASH_APPLY_STOP; } + /* we can be modified and already be compressed, such as when chmod() is executed */ + if (entry->flags & PHAR_ENT_COMPRESSION_MASK && (entry->old_flags == entry->flags || !entry->old_flags)) { + not_really_modified = 1; + goto is_compressed; + } + if (-1 == phar_seek_efp(entry, 0, SEEK_SET, 0, 0 TSRMLS_CC)) { spprintf(p->error, 0, "unable to seek to start of file \"%s\" to zip-based phar \"%s\"", entry->filename, entry->phar->fname); return ZEND_HASH_APPLY_STOP; @@ -791,6 +796,7 @@ static int phar_zip_changed_apply(void *data, void *arg TSRMLS_DC) /* {{{ */ entry->old_flags = entry->flags; entry->is_modified = 1; } else { +is_compressed: central.uncompsize = local.uncompsize = PHAR_SET_32(entry->uncompressed_filesize); central.compsize = local.compsize = PHAR_SET_32(entry->compressed_filesize); @@ -872,7 +878,7 @@ continue_dir: return ZEND_HASH_APPLY_STOP; } - if (entry->is_modified) { + if (!not_really_modified && entry->is_modified) { if (entry->cfp) { if (entry->compressed_filesize != php_stream_copy_to_stream(entry->cfp, p->filefp, entry->compressed_filesize)) { spprintf(p->error, 0, "unable to write compressed contents of file \"%s\" in zip-based phar \"%s\"", entry->filename, entry->phar->fname); @@ -900,6 +906,7 @@ continue_dir: entry->is_modified = 0; } else { + entry->is_modified = 0; if (entry->fp_refcount) { /* open file pointers refer to this fp, do not free the stream */ switch (entry->fp_type) { -- 2.50.1