@@ -1934,7 +1934,8 @@ static zend_result phar_copy_file_contents(phar_entry_info *entry, php_stream *f
19341934{
19351935 char *error;
19361936 zend_off_t offset;
1937- phar_entry_info *link;
1937+
1938+ ZEND_ASSERT(!entry->link);
19381939
19391940 if (FAILURE == phar_open_entry_fp(entry, &error, 1)) {
19401941 if (error) {
@@ -1949,26 +1950,14 @@ static zend_result phar_copy_file_contents(phar_entry_info *entry, php_stream *f
19491950 }
19501951
19511952 /* copy old contents in entirety */
1952- phar_seek_efp(entry, 0, SEEK_SET, 0, 1 );
1953+ phar_seek_efp(entry, 0, SEEK_SET, 0, 0 );
19531954 offset = php_stream_tell(fp);
1954- link = phar_get_link_source(entry);
1955-
1956- if (!link) {
1957- link = entry;
1958- }
1959-
1960- if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(link, 0), fp, link->uncompressed_filesize, NULL)) {
1955+ if (SUCCESS != php_stream_copy_to_stream_ex(phar_get_efp(entry, 0), fp, entry->uncompressed_filesize, NULL)) {
19611956 zend_throw_exception_ex(spl_ce_UnexpectedValueException, 0,
19621957 "Cannot convert phar archive \"%s\", unable to copy entry \"%s\" contents", entry->phar->fname, entry->filename);
19631958 return FAILURE;
19641959 }
19651960
1966- if (entry->fp_type == PHAR_MOD) {
1967- /* save for potential restore on error */
1968- entry->cfp = entry->fp;
1969- entry->fp = NULL;
1970- }
1971-
19721961 /* set new location of file contents */
19731962 entry->fp_type = PHAR_FP;
19741963 entry->offset = offset;
@@ -2307,6 +2296,10 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert
23072296 return NULL;
23082297 }
23092298no_copy:
2299+ /* Reset file pointers, they have to be reset here such that if a copy happens the original
2300+ * source fp can be accessed. */
2301+ newentry.fp = NULL;
2302+ newentry.cfp = NULL;
23102303 newentry.filename = estrndup(newentry.filename, newentry.filename_len);
23112304
23122305 phar_metadata_tracker_clone(&newentry.metadata_tracker);
0 commit comments