[PHP-CVS] cvs: php-src /ext/phar stream.c /ext/phar/tests bug47085.phpt
cellog Tue Feb 3 18:29:46 2009 UTC Modified files: /php-src/ext/phar stream.c /php-src/ext/phar/tests bug47085.phpt Log: MFB: fix bug #47085:rename() returns true even if the file in PHAR does not exist http://cvs.php.net/viewvc.cgi/php-src/ext/phar/stream.c?r1=1.39r2=1.40diff_format=u Index: php-src/ext/phar/stream.c diff -u php-src/ext/phar/stream.c:1.39 php-src/ext/phar/stream.c:1.40 --- php-src/ext/phar/stream.c:1.39 Wed Dec 31 11:12:35 2008 +++ php-src/ext/phar/stream.c Tue Feb 3 18:29:46 2009 @@ -888,6 +888,14 @@ is_dir = entry-is_dir; } else { is_dir = zend_hash_exists((phar-virtual_dirs), resource_from-path+1, strlen(resource_from-path)-1); + if (!is_dir) { + /* file does not exist */ + 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\ from extracted phar archive, source does not exist, url_from, url_to); + return 0; + + } } /* Rename directory. Update all nested paths */ http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/bug47085.phpt?r1=1.1r2=1.2diff_format=u Index: php-src/ext/phar/tests/bug47085.phpt diff -u /dev/null php-src/ext/phar/tests/bug47085.phpt:1.2 --- /dev/null Tue Feb 3 18:29:46 2009 +++ php-src/ext/phar/tests/bug47085.phptTue Feb 3 18:29:46 2009 @@ -0,0 +1,24 @@ +--TEST-- +Phar: PHP bug #47085: rename() returns true even if the file in PHAR does not exist +--SKIPIF-- +?php if (!extension_loaded(phar)) die(skip); ? +--INI-- +phar.require_hash=0 +phar.readonly=0 +--FILE-- +?php +$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar'; + +$phar = new Phar($fname, 0, 'a.phar'); +$phar['x'] = 'hi'; +unset($phar); +rename(phar://a.phar/x, phar://a.phar/y); +var_dump(rename(phar://a.phar/x, phar://a.phar/y)); +? +===DONE=== +--CLEAN-- +?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar');? +--EXPECTF-- +Warning: rename(): phar error: cannot rename phar://a.phar/x to phar://a.phar/y from extracted phar archive, source does not exist in %sbug47085.php on line %d +bool(false) +===DONE=== \ No newline at end of file -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/phar stream.c util.c /ext/phar/tests/tar links6.phpt /ext/phar/tests/tar/files links.phar.tar
cellog Sat Oct 11 22:12:18 2008 UTC Added files: /php-src/ext/phar/tests/tar/files links.phar.tar Modified files: /php-src/ext/phar stream.c util.c /php-src/ext/phar/tests/tar links6.phpt Log: MFB: fix reading links from streams (works with PharFileInfo-getContent()) http://cvs.php.net/viewvc.cgi/php-src/ext/phar/stream.c?r1=1.36r2=1.37diff_format=u Index: php-src/ext/phar/stream.c diff -u php-src/ext/phar/stream.c:1.36 php-src/ext/phar/stream.c:1.37 --- php-src/ext/phar/stream.c:1.36 Fri Sep 26 23:35:11 2008 +++ php-src/ext/phar/stream.c Sat Oct 11 22:12:18 2008 @@ -359,8 +359,15 @@ { phar_entry_data *data = (phar_entry_data *)stream-abstract; size_t got; + phar_entry_info *entry; + + if (data-internal_file-link) { + entry = phar_get_link_source(data-internal_file TSRMLS_CC); + } else { + entry = data-internal_file; + } - if (data-internal_file-is_deleted) { + if (entry-is_deleted) { stream-eof = 1; return 0; } @@ -368,9 +375,9 @@ /* use our proxy position */ php_stream_seek(data-fp, data-position + data-zero, SEEK_SET); - got = php_stream_read(data-fp, buf, MIN(count, data-internal_file-uncompressed_filesize - data-position)); + got = php_stream_read(data-fp, buf, MIN(count, entry-uncompressed_filesize - data-position)); data-position = php_stream_tell(data-fp) - data-zero; - stream-eof = (data-position == (off_t) data-internal_file-uncompressed_filesize); + stream-eof = (data-position == (off_t) entry-uncompressed_filesize); return got; } http://cvs.php.net/viewvc.cgi/php-src/ext/phar/util.c?r1=1.66r2=1.67diff_format=u Index: php-src/ext/phar/util.c diff -u php-src/ext/phar/util.c:1.66 php-src/ext/phar/util.c:1.67 --- php-src/ext/phar/util.c:1.66Thu Oct 9 00:51:27 2008 +++ php-src/ext/phar/util.c Sat Oct 11 22:12:18 2008 @@ -18,7 +18,7 @@ +--+ */ -/* $Id: util.c,v 1.66 2008/10/09 00:51:27 cellog Exp $ */ +/* $Id: util.c,v 1.67 2008/10/11 22:12:18 cellog Exp $ */ #include phar_internal.h @@ -65,12 +65,13 @@ phar_entry_info *phar_get_link_source(phar_entry_info *entry TSRMLS_DC) /* {{{ */ { phar_entry_info *link_entry; - char *link = phar_get_link_location(entry TSRMLS_CC); + char *link; if (!entry-link) { return entry; } + link = phar_get_link_location(entry TSRMLS_CC); if (SUCCESS == zend_hash_find((entry-phar-manifest), entry-link, strlen(entry-link), (void **)link_entry) || SUCCESS == zend_hash_find((entry-phar-manifest), link, strlen(link), (void **)link_entry)) { if (link != entry-link) { @@ -680,13 +681,13 @@ phar_seek_efp(entry, 0, SEEK_END, 0, 0 TSRMLS_CC); } } else { - if (entry-link) { - efree(entry-link); - entry-link = NULL; - entry-tar_type = (entry-is_tar ? TAR_FILE : '\0'); - } - if (for_write) { + if (entry-link) { + efree(entry-link); + entry-link = NULL; + entry-tar_type = (entry-is_tar ? TAR_FILE : '\0'); + } + if (for_trunc) { if (FAILURE == phar_create_writeable_entry(phar, entry, error TSRMLS_CC)) { return FAILURE; @@ -711,7 +712,11 @@ (*ret)-is_zip = entry-is_zip; (*ret)-is_tar = entry-is_tar; (*ret)-fp = phar_get_efp(entry, 1 TSRMLS_CC); - (*ret)-zero = phar_get_fp_offset(entry TSRMLS_CC); + if (entry-link) { + (*ret)-zero = phar_get_fp_offset(phar_get_link_source(entry TSRMLS_CC) TSRMLS_CC); + } else { + (*ret)-zero = phar_get_fp_offset(entry TSRMLS_CC); + } if (!phar-is_persistent) { ++(entry-fp_refcount); http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/tar/links6.phpt?r1=1.1r2=1.2diff_format=u Index: php-src/ext/phar/tests/tar/links6.phpt diff -u /dev/null php-src/ext/phar/tests/tar/links6.phpt:1.2 --- /dev/null Sat Oct 11 22:12:18 2008 +++ php-src/ext/phar/tests/tar/links6.phpt Sat Oct 11 22:12:18 2008 @@ -0,0 +1,21 @@ +--TEST-- +Phar: test nested linked files +--SKIPIF-- +?php +if (!extension_loaded(phar)) die(skip); +? +--FILE-- +?php +echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link2'); +echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link1'); +echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/testit.txt'); +? +===DONE===
[PHP-CVS] cvs: php-src /ext/phar stream.c /ext/phar/tests/tar links6.phpt
cellog Sat Oct 11 22:21:07 2008 UTC Modified files: /php-src/ext/phar stream.c /php-src/ext/phar/tests/tar links6.phpt Log: MFB: fix links for fseek as well http://cvs.php.net/viewvc.cgi/php-src/ext/phar/stream.c?r1=1.37r2=1.38diff_format=u Index: php-src/ext/phar/stream.c diff -u php-src/ext/phar/stream.c:1.37 php-src/ext/phar/stream.c:1.38 --- php-src/ext/phar/stream.c:1.37 Sat Oct 11 22:12:18 2008 +++ php-src/ext/phar/stream.c Sat Oct 11 22:21:07 2008 @@ -389,12 +389,19 @@ static int phar_stream_seek(php_stream *stream, off_t offset, int whence, off_t *newoffset TSRMLS_DC) /* {{{ */ { phar_entry_data *data = (phar_entry_data *)stream-abstract; - + phar_entry_info *entry; int res; off_t temp; + + if (data-internal_file-link) { + entry = phar_get_link_source(data-internal_file TSRMLS_CC); + } else { + entry = data-internal_file; + } + switch (whence) { case SEEK_END : - temp = data-zero + data-internal_file-uncompressed_filesize + offset; + temp = data-zero + entry-uncompressed_filesize + offset; break; case SEEK_CUR : temp = data-zero + data-position + offset; @@ -403,7 +410,7 @@ temp = data-zero + offset; break; } - if (temp data-zero + (off_t) data-internal_file-uncompressed_filesize) { + if (temp data-zero + (off_t) entry-uncompressed_filesize) { *newoffset = -1; return -1; } http://cvs.php.net/viewvc.cgi/php-src/ext/phar/tests/tar/links6.phpt?r1=1.2r2=1.3diff_format=u Index: php-src/ext/phar/tests/tar/links6.phpt diff -u php-src/ext/phar/tests/tar/links6.phpt:1.2 php-src/ext/phar/tests/tar/links6.phpt:1.3 --- php-src/ext/phar/tests/tar/links6.phpt:1.2 Sat Oct 11 22:12:18 2008 +++ php-src/ext/phar/tests/tar/links6.phpt Sat Oct 11 22:21:07 2008 @@ -9,6 +9,10 @@ echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link2'); echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link1'); echo file_get_contents('phar://' . dirname(__FILE__) . '/files/links.phar.tar/testit.txt'); + +$a = fopen('phar://' . dirname(__FILE__) . '/files/links.phar.tar/link2', 'r'); +fseek($a, 3); +echo fread($a, 10); ? ===DONE=== --EXPECT-- @@ -18,4 +22,6 @@ hi there +there + ===DONE=== \ No newline at end of file -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-CVS] cvs: php-src /ext/phar stream.c
sfoxFri Aug 1 16:28:19 2008 UTC Modified files: /php-src/ext/phar stream.c Log: - Merge Dmitry's changes from PHP_5_3 branch http://cvs.php.net/viewvc.cgi/php-src/ext/phar/stream.c?r1=1.32r2=1.33diff_format=u Index: php-src/ext/phar/stream.c diff -u php-src/ext/phar/stream.c:1.32 php-src/ext/phar/stream.c:1.33 --- php-src/ext/phar/stream.c:1.32 Fri Aug 1 13:45:06 2008 +++ php-src/ext/phar/stream.c Fri Aug 1 16:28:19 2008 @@ -916,7 +916,11 @@ entry-filename_len = new_key_len; PHAR_ZSTR(new_str_key, new_key); +#if PHP_VERSION_ID 50300 zend_hash_update_current_key_ex(phar-manifest, key_type, new_key, new_key_len, 0, NULL); +#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); } } @@ -938,7 +942,11 @@ new_str_key[new_key_len] = 0; PHAR_ZSTR(new_str_key, new_key); +#if PHP_VERSION_ID 50300 zend_hash_update_current_key_ex(phar-virtual_dirs, key_type, new_key, new_key_len, 0, NULL); +#else + zend_hash_update_current_key_ex(phar-virtual_dirs, key_type, new_key, new_key_len, 0, HASH_UPDATE_KEY_ANYWAY, NULL); +#endif efree(new_str_key); } } @@ -961,7 +969,11 @@ new_str_key[new_key_len] = 0; PHAR_ZSTR(new_str_key, new_key); +#if PHP_VERSION_ID 50300 zend_hash_update_current_key_ex(phar-mounted_dirs, key_type, new_key, new_key_len, 0, NULL); +#else + zend_hash_update_current_key_ex(phar-mounted_dirs, key_type, new_key, new_key_len, 0, HASH_UPDATE_KEY_ANYWAY, NULL); +#endif efree(new_str_key); } } -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php