cellog Thu May 22 06:33:09 2008 UTC Modified files: (Branch: PHP_5_3) /php-src/ext/phar phar.c phar_object.c tar.c util.c zip.c Log: major fixes * found felipe's segfault in util.c and fixed the segfault (3 tests fail due to odd behavior of . and .. on this machine) * fixed serious flaws in the setting/resetting of is_data - now it works properly. Assume all new PharData are tar-based, and allow passing Phar::ZIP to PharData constructor to override this * fix broken earlier commit, introduced segfault that broke 20 tests here
http://cvs.php.net/viewvc.cgi/php-src/ext/phar/phar.c?r1=1.370.2.4&r2=1.370.2.5&diff_format=u Index: php-src/ext/phar/phar.c diff -u php-src/ext/phar/phar.c:1.370.2.4 php-src/ext/phar/phar.c:1.370.2.5 --- php-src/ext/phar/phar.c:1.370.2.4 Wed May 21 22:00:43 2008 +++ php-src/ext/phar/phar.c Thu May 22 06:33:08 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar.c,v 1.370.2.4 2008/05/21 22:00:43 cellog Exp $ */ +/* $Id: phar.c,v 1.370.2.5 2008/05/22 06:33:08 cellog Exp $ */ #define PHAR_MAIN 1 #include "phar_internal.h" @@ -406,7 +406,6 @@ } } } - phar->is_data = is_data && (phar->is_tar || phar->is_zip); if (pphar) { *pphar = phar; } @@ -1033,12 +1032,12 @@ } if (ext_len > 3 && (z = memchr(ext_str, 'z', ext_len)) && ((ext_str + ext_len) - z >= 2) && !memcmp(z + 1, "ip", 2)) { - // assume zip-based phar + /* assume zip-based phar */ return phar_open_or_create_zip(fname, fname_len, alias, alias_len, is_data, options, pphar, error TSRMLS_CC); } if (ext_len > 3 && (z = memchr(ext_str, 't', ext_len)) && ((ext_str + ext_len) - z >= 2) && !memcmp(z + 1, "ar", 2)) { - // assume tar-based phar + /* assume tar-based phar */ return phar_open_or_create_tar(fname, fname_len, alias, alias_len, is_data, options, pphar, error TSRMLS_CC); } @@ -1140,6 +1139,9 @@ if (is_data) { alias = NULL; alias_len = 0; + mydata->is_data = 1; + /* assume tar format, PharData can specify other */ + mydata->is_tar = 1; } else { phar_archive_data **fd_ptr; @@ -3025,7 +3027,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.4 $"); + php_info_print_table_row(2, "CVS revision", "$Revision: 1.370.2.5 $"); 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_object.c?r1=1.266.2.10&r2=1.266.2.11&diff_format=u Index: php-src/ext/phar/phar_object.c diff -u php-src/ext/phar/phar_object.c:1.266.2.10 php-src/ext/phar/phar_object.c:1.266.2.11 --- php-src/ext/phar/phar_object.c:1.266.2.10 Wed May 21 22:52:30 2008 +++ php-src/ext/phar/phar_object.c Thu May 22 06:33:09 2008 @@ -17,7 +17,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: phar_object.c,v 1.266.2.10 2008/05/21 22:52:30 felipe Exp $ */ +/* $Id: phar_object.c,v 1.266.2.11 2008/05/22 06:33:09 cellog Exp $ */ #include "phar_internal.h" #include "func_interceptors.h" @@ -1102,7 +1102,7 @@ /* {{{ proto void Phar::__construct(string fname [, int flags [, string alias]]) * Construct a Phar archive object - * {{{ proto void PharData::__construct(string fname [, int flags [, string alias]]) + * {{{ proto void PharData::__construct(string fname [[, int flags [, string alias]], int file format = Phar::TAR]) * Construct a PharData archive object */ PHP_METHOD(Phar, __construct) @@ -1112,22 +1112,13 @@ #else char *fname, *alias = NULL, *error, *arch = NULL, *entry = NULL, *save_fname, *objname; int fname_len, alias_len = 0, arch_len, entry_len, is_data; - long flags = 0; + long flags = 0, format = 0; phar_archive_object *phar_obj; phar_archive_data *phar_data; zval *zobj = getThis(), arg1, arg2; - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len) == FAILURE) { - return; - } - phar_obj = (phar_archive_object*)zend_object_store_get_object(getThis() TSRMLS_CC); - if (phar_obj->arc.archive) { - zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot call constructor twice"); - return; - } - PHAR_STR(phar_obj->std.ce->name, objname); if (!strncmp(objname, "PharData", 8)) { @@ -1136,6 +1127,21 @@ is_data = 0; } + if (is_data) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls!l", &fname, &fname_len, &flags, &alias, &alias_len, &format) == FAILURE) { + return; + } + } else { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|ls!", &fname, &fname_len, &flags, &alias, &alias_len) == FAILURE) { + return; + } + } + + if (phar_obj->arc.archive) { + zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Cannot call constructor twice"); + return; + } + if (SUCCESS == phar_split_fname(fname, fname_len, &arch, &arch_len, &entry, &entry_len, !is_data, 2 TSRMLS_CC)) { /* use arch (the basename for the archive) for fname instead of fname */ /* this allows support for RecursiveDirectoryIterator of subdirectories */ @@ -1175,11 +1181,26 @@ return; } + if (is_data && phar_data->is_tar && phar_data->is_brandnew && format == PHAR_FORMAT_ZIP) { + phar_data->is_zip = 1; + phar_data->is_tar = 0; + } if (fname == arch) { efree(arch); fname = save_fname; } + if ((is_data && !phar_data->is_data) || (!is_data && phar_data->is_data)) { + if (is_data) { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "PharData class can only be used for non-executable tar and zip archives"); + } else { + zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0 TSRMLS_CC, + "Phar class can only be used for executable tar and zip archives"); + } + efree(entry); + return; + } is_data = phar_data->is_data; ++(phar_data->refcount); phar_obj->arc.archive = phar_data; @@ -1819,7 +1840,7 @@ char *error; const char *pcr_error; int ext_len = ext ? strlen(ext) : 0; - phar_archive_data **pphar; + phar_archive_data **pphar = NULL; if (!ext) { if (phar->is_zip) { @@ -1887,6 +1908,7 @@ basepath = estrndup(oldpath, strlen(oldpath) - strlen(oldname)); phar->fname_len = spprintf(&newpath, 0, "%s%s", basepath, newname); phar->fname = newpath; + phar->ext = newpath + phar->fname_len - strlen(ext) - 1; efree(basepath); efree(newname); @@ -1901,6 +1923,7 @@ phar->fp = NULL; phar_destroy_phar_data(phar TSRMLS_CC); phar = *pphar; + phar->refcount++; newpath = oldpath; goto its_ok; } @@ -1938,7 +1961,7 @@ phar->alias_len = 0; } - if (SUCCESS != zend_hash_update(&(PHAR_GLOBALS->phar_fname_map), newpath, phar->fname_len, (void*)&phar, sizeof(phar_archive_data*), NULL)) { + if ((!pphar || phar == *pphar) && SUCCESS != zend_hash_update(&(PHAR_GLOBALS->phar_fname_map), newpath, phar->fname_len, (void*)&phar, sizeof(phar_archive_data*), NULL)) { efree(oldpath); zend_throw_exception_ex(spl_ce_BadMethodCallException, 0 TSRMLS_CC, "Unable to add newly converted phar \"%s\" to the list of phars", phar->fname); return NULL; @@ -4416,6 +4439,7 @@ ZEND_ARG_INFO(0, filename) ZEND_ARG_INFO(0, flags) ZEND_ARG_INFO(0, alias) + ZEND_ARG_INFO(0, fileformat) ZEND_END_ARG_INFO(); static http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tar.c?r1=1.55.2.2&r2=1.55.2.3&diff_format=u Index: php-src/ext/phar/tar.c diff -u php-src/ext/phar/tar.c:1.55.2.2 php-src/ext/phar/tar.c:1.55.2.3 --- php-src/ext/phar/tar.c:1.55.2.2 Wed May 21 22:00:43 2008 +++ php-src/ext/phar/tar.c Thu May 22 06:33:09 2008 @@ -141,6 +141,7 @@ if (phar->is_brandnew) { phar->is_tar = 1; + phar->is_zip = 0; phar->internal_file_start = 0; return SUCCESS; } @@ -422,6 +423,12 @@ #endif myphar->fname_len = fname_len; p = strrchr(myphar->fname, '/'); + + if (zend_hash_exists(&(myphar->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1)) { + myphar->is_data = 0; + } else { + myphar->is_data = 1; + } if (p) { myphar->ext = memchr(p, '.', (myphar->fname + fname_len) - p); if (myphar->ext == p) { http://cvs.php.net/viewvc.cgi/php-src/ext/phar/util.c?r1=1.55.2.2&r2=1.55.2.3&diff_format=u Index: php-src/ext/phar/util.c diff -u php-src/ext/phar/util.c:1.55.2.2 php-src/ext/phar/util.c:1.55.2.3 --- php-src/ext/phar/util.c:1.55.2.2 Thu May 15 16:09:00 2008 +++ php-src/ext/phar/util.c Thu May 22 06:33:09 2008 @@ -18,7 +18,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: util.c,v 1.55.2.2 2008/05/15 16:09:00 cellog Exp $ */ +/* $Id: util.c,v 1.55.2.3 2008/05/22 06:33:09 cellog Exp $ */ #include "phar_internal.h" #if !defined(PHP_VERSION_ID) || PHP_VERSION_ID < 50300 @@ -1172,6 +1172,9 @@ return NULL; } if (is_dir) { + if (!path_len || path_len == 1) { + return NULL; + } path_len--; } if (SUCCESS == zend_hash_find(&phar->manifest, path, path_len, (void**)&entry)) { http://cvs.php.net/viewvc.cgi/php-src/ext/phar/zip.c?r1=1.47.2.1&r2=1.47.2.2&diff_format=u Index: php-src/ext/phar/zip.c diff -u php-src/ext/phar/zip.c:1.47.2.1 php-src/ext/phar/zip.c:1.47.2.2 --- php-src/ext/phar/zip.c:1.47.2.1 Sat May 17 20:07:22 2008 +++ php-src/ext/phar/zip.c Thu May 22 06:33:09 2008 @@ -443,6 +443,11 @@ zend_hash_add(&mydata->manifest, entry.filename, entry.filename_len, (void *)&entry,sizeof(phar_entry_info), NULL); } mydata->fp = fp; + if (zend_hash_exists(&(mydata->manifest), ".phar/stub.php", sizeof(".phar/stub.php")-1)) { + mydata->is_data = 0; + } else { + mydata->is_data = 1; + } zend_hash_add(&(PHAR_GLOBALS->phar_fname_map), mydata->fname, fname_len, (void*)&mydata, sizeof(phar_archive_data*), NULL); if (actual_alias) { phar_archive_data **fd_ptr; @@ -522,6 +527,7 @@ if (phar->is_brandnew) { phar->internal_file_start = 0; phar->is_zip = 1; + phar->is_tar = 0; return SUCCESS; }
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php