@@ -1934,7 +1934,8 @@ static zend_result phar_copy_file_contents(phar_entry_info *entry, php_stream *f
1934
1934
{
1935
1935
char * error ;
1936
1936
zend_off_t offset ;
1937
- phar_entry_info * link ;
1937
+
1938
+ ZEND_ASSERT (!entry -> link );
1938
1939
1939
1940
if (FAILURE == phar_open_entry_fp (entry , & error , 1 )) {
1940
1941
if (error ) {
@@ -1949,26 +1950,14 @@ static zend_result phar_copy_file_contents(phar_entry_info *entry, php_stream *f
1949
1950
}
1950
1951
1951
1952
/* 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 );
1953
1954
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 )) {
1961
1956
zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
1962
1957
"Cannot convert phar archive \"%s\", unable to copy entry \"%s\" contents" , entry -> phar -> fname , ZSTR_VAL (entry -> filename ));
1963
1958
return FAILURE ;
1964
1959
}
1965
1960
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
-
1972
1961
/* set new location of file contents */
1973
1962
entry -> fp_type = PHAR_FP ;
1974
1963
entry -> offset = offset ;
@@ -2307,6 +2296,10 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert
2307
2296
return NULL ;
2308
2297
}
2309
2298
no_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 ;
2310
2303
newentry .filename = zend_string_copy (newentry .filename );
2311
2304
2312
2305
phar_metadata_tracker_clone (& newentry .metadata_tracker );
0 commit comments