cellog Thu Aug 21 05:17:29 2008 UTC Added files: (Branch: PHP_5_3) /php-src/ext/phar/tests/zip bzip2.phpt /php-src/ext/phar/tests/zip/files bzip2.zip
Modified files: /php-src/ext/phar phar.c phar.phar phar_internal.h stream.c stream.h util.c zip.c Log: fix bug #45792: bz2 compressed files in zip failure
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.370.2.39&r2=1.370.2.40&diff_format=u Index: php-src/ext/phar/phar.c diff -u php-src/ext/phar/phar.c:1.370.2.39 php-src/ext/phar/phar.c:1.370.2.40 --- php-src/ext/phar/phar.c:1.370.2.39 Thu Aug 14 13:01:28 2008 +++ php-src/ext/phar/phar.c Thu Aug 21 05:17:26 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar.c,v 1.370.2.39 2008/08/14 13:01:28 dmitry Exp $ */ +/* $Id: phar.c,v 1.370.2.40 2008/08/21 05:17:26 cellog Exp $ */ #define PHAR_MAIN 1 #include "phar_internal.h" @@ -2383,7 +2383,7 @@ /** * 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 +2394,7 @@ *error = NULL; } - if (entry->is_zip) { + if (entry->is_zip && process_zip > 0) { /* verify local file header */ phar_zip_file_header local; @@ -2424,6 +2424,7 @@ idata->zero = entry->offset_abs; } } + if (process_zip == 1) return SUCCESS; php_stream_seek(fp, idata->zero, SEEK_SET); @@ -2437,7 +2438,7 @@ 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; } } @@ -3733,7 +3734,7 @@ 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, "CVS revision", "$Revision: 1.370.2.39 $"); + php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.40 $"); 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"); http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.phar?r1=1.7.2.30&r2=1.7.2.31&diff_format=u Index: php-src/ext/phar/phar.phar http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar_internal.h?r1=1.109.2.23&r2=1.109.2.24&diff_format=u Index: php-src/ext/phar/phar_internal.h diff -u php-src/ext/phar/phar_internal.h:1.109.2.23 php-src/ext/phar/phar_internal.h:1.109.2.24 --- php-src/ext/phar/phar_internal.h:1.109.2.23 Fri Aug 1 13:48:44 2008 +++ php-src/ext/phar/phar_internal.h Thu Aug 21 05:17:27 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar_internal.h,v 1.109.2.23 2008/08/01 13:48:44 sfox Exp $ */ +/* $Id: phar_internal.h,v 1.109.2.24 2008/08/21 05:17:27 cellog Exp $ */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -576,6 +576,7 @@ 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); http://cvs.php.net/viewvc.cgi/php-src/ext/phar/stream.c?r1=1.27.2.13&r2=1.27.2.14&diff_format=u Index: php-src/ext/phar/stream.c diff -u php-src/ext/phar/stream.c:1.27.2.13 php-src/ext/phar/stream.c:1.27.2.14 --- php-src/ext/phar/stream.c:1.27.2.13 Fri Aug 1 14:22:48 2008 +++ php-src/ext/phar/stream.c Thu Aug 21 05:17:27 2008 @@ -307,8 +307,9 @@ #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; http://cvs.php.net/viewvc.cgi/php-src/ext/phar/stream.h?r1=1.3.2.2&r2=1.3.2.3&diff_format=u Index: php-src/ext/phar/stream.h diff -u php-src/ext/phar/stream.h:1.3.2.2 php-src/ext/phar/stream.h:1.3.2.3 --- php-src/ext/phar/stream.h:1.3.2.2 Fri Aug 1 13:48:44 2008 +++ php-src/ext/phar/stream.h Thu Aug 21 05:17:27 2008 @@ -17,10 +17,9 @@ +----------------------------------------------------------------------+ */ -/* $Id: stream.h,v 1.3.2.2 2008/08/01 13:48:44 sfox Exp $ */ +/* $Id: stream.h,v 1.3.2.3 2008/08/21 05:17:27 cellog Exp $ */ 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); http://cvs.php.net/viewvc.cgi/php-src/ext/phar/util.c?r1=1.55.2.28&r2=1.55.2.29&diff_format=u Index: php-src/ext/phar/util.c diff -u php-src/ext/phar/util.c:1.55.2.28 php-src/ext/phar/util.c:1.55.2.29 --- php-src/ext/phar/util.c:1.55.2.28 Fri Aug 1 13:48:45 2008 +++ php-src/ext/phar/util.c Thu Aug 21 05:17:27 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: util.c,v 1.55.2.28 2008/08/01 13:48:45 sfox Exp $ */ +/* $Id: util.c,v 1.55.2.29 2008/08/21 05:17:27 cellog Exp $ */ #include "phar_internal.h" @@ -913,6 +913,7 @@ 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 +922,10 @@ } } + 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 +946,13 @@ } 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 +964,14 @@ } } + 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 +1011,11 @@ /* 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; } /* }}} */ http://cvs.php.net/viewvc.cgi/php-src/ext/phar/zip.c?r1=1.47.2.16&r2=1.47.2.17&diff_format=u Index: php-src/ext/phar/zip.c diff -u php-src/ext/phar/zip.c:1.47.2.16 php-src/ext/phar/zip.c:1.47.2.17 --- php-src/ext/phar/zip.c:1.47.2.16 Fri Aug 1 13:48:45 2008 +++ php-src/ext/phar/zip.c Thu Aug 21 05:17:27 2008 @@ -655,6 +655,7 @@ 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 +724,12 @@ 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 +798,7 @@ 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 +880,7 @@ 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 +908,7 @@ 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) { http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/zip/bzip2.phpt?view=markup&rev=1.1 Index: php-src/ext/phar/tests/zip/bzip2.phpt +++ php-src/ext/phar/tests/zip/bzip2.phpt http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/zip/files/bzip2.zip?view=markup&rev=1.1 Index: php-src/ext/phar/tests/zip/files/bzip2.zip +++ php-src/ext/phar/tests/zip/files/bzip2.zip
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php