]> granicus.if.org Git - php/commitdiff
fix offset detection in tar files
authorGreg Beaver <cellog@php.net>
Wed, 21 May 2008 22:00:43 +0000 (22:00 +0000)
committerGreg Beaver <cellog@php.net>
Wed, 21 May 2008 22:00:43 +0000 (22:00 +0000)
ext/phar/phar.c
ext/phar/phar_internal.h
ext/phar/phar_object.c
ext/phar/tar.c

index 54ee0cad3494aa8f37746503eb6c7ef59de1778e..f432c0692604059d043146ad8a17a48384c4e354 100644 (file)
@@ -101,7 +101,7 @@ PHP_INI_END()
  * When all uses of a phar have been concluded, this frees the manifest
  * and the phar slot
  */
-static void phar_destroy_phar_data(phar_archive_data *phar TSRMLS_DC) /* {{{ */
+void phar_destroy_phar_data(phar_archive_data *phar TSRMLS_DC) /* {{{ */
 {
        if (phar->alias && phar->alias != phar->fname) {
                efree(phar->alias);
index 185b1e2ffec57ca89d34ae80f9b1c472c6829364..b467fbe2d822871f83a573466d25e65d43a90b7a 100755 (executable)
@@ -395,6 +395,7 @@ static inline int phar_validate_alias(const char *alias, int alias_len) /* {{{ *
 void phar_request_initialize(TSRMLS_D);
 
 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_open_filename(char *fname, int fname_len, char *alias, int alias_len, int options, phar_archive_data** pphar, char **error TSRMLS_DC);
index cc0156fb1c9bb0337e344e8193f9810a3f95c8a7..e145a289a70d20b9eb133591a8e2de1fec4e36af 100755 (executable)
@@ -1893,6 +1893,15 @@ static zval *phar_rename_archive(phar_archive_data *phar, char *ext, zend_bool c
        if (SUCCESS == zend_hash_find(&(PHAR_GLOBALS->phar_fname_map), newpath, phar->fname_len, (void **) &pphar)) {
                if ((*pphar)->fname_len == phar->fname_len && !memcmp((*pphar)->fname, phar->fname, phar->fname_len)) {
                        if (!zend_hash_num_elements(&phar->manifest)) {
+                               (*pphar)->is_tar = phar->is_tar;
+                               (*pphar)->is_zip = phar->is_zip;
+                               (*pphar)->is_data = phar->is_data;
+                               (*pphar)->flags = phar->flags;
+                               (*pphar)->fp = phar->fp;
+                               phar->fp = NULL;
+                               phar_destroy_phar_data(phar);
+                               phar = *pphar;
+                               newpath = oldpath;
                                goto its_ok;
                        }
                }
index bcde5dc0a017227231c1a064418507db426c1cf1..802f6149db764b2963036399f76e2f38a2a3a5f4 100644 (file)
@@ -225,10 +225,11 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
        entry.is_tar = 1;
        entry.is_crc_checked = 1;
        entry.phar = myphar;
+       pos += sizeof(buf);
        do {
                phar_entry_info *newentry;
 
-               pos += sizeof(buf);
+               pos = php_stream_tell(fp);
                hdr = (tar_header*) buf;
                sum1 = phar_tar_number(hdr->checksum, sizeof(hdr->checksum));
                if (sum1 == 0 && phar_tar_checksum(buf, sizeof(buf)) == 0) {
@@ -385,7 +386,6 @@ int phar_open_tarfile(php_stream* fp, char *fname, int fname_len, char *alias, i
                        }
                }
                size = (size+511)&~511;
-               pos += size;
                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);