@@ -433,7 +433,7 @@ void phar_entry_remove(phar_entry_data *idata, char **error) /* {{{ */
433
433
}
434
434
435
435
if (!phar -> donotflush ) {
436
- phar_flush (phar , 0 , 0 , 0 , error );
436
+ phar_flush (phar , error );
437
437
}
438
438
}
439
439
/* }}} */
@@ -2522,27 +2522,31 @@ zend_string *phar_create_default_stub(const char *index_php, const char *web_ind
2522
2522
}
2523
2523
/* }}} */
2524
2524
2525
+ int phar_flush (phar_archive_data * phar , char * * error ) {
2526
+ return phar_flush_ex (phar , NULL , false, error );
2527
+ }
2528
+
2525
2529
/**
2526
2530
* Save phar contents to disk
2527
2531
*
2528
2532
* user_stub contains either a string, or a resource pointer, if len is a negative length.
2529
2533
* user_stub and len should be both 0 if the default or existing stub should be used
2530
2534
*/
2531
- int phar_flush (phar_archive_data * phar , char * user_stub , zend_long len , int convert , char * * error ) /* {{{ */
2535
+ int phar_flush_ex (phar_archive_data * phar , zend_string * user_stub , bool is_default_stub , char * * error ) /* {{{ */
2532
2536
{
2533
2537
char halt_stub [] = "__HALT_COMPILER();" ;
2534
2538
zend_string * newstub ;
2535
2539
phar_entry_info * entry , * newentry ;
2536
2540
size_t halt_offset ;
2537
2541
int restore_alias_len , global_flags = 0 , closeoldfile ;
2538
- char * pos , has_dirs = 0 ;
2542
+ bool has_dirs = 0 ;
2539
2543
char manifest [18 ], entry_buffer [24 ];
2540
2544
zend_off_t manifest_ftell ;
2541
2545
zend_long offset ;
2542
2546
size_t wrote ;
2543
2547
uint32_t manifest_len , mytime , new_manifest_count ;
2544
2548
uint32_t newcrc32 ;
2545
- php_stream * file , * oldfile , * newfile , * stubfile ;
2549
+ php_stream * file , * oldfile , * newfile ;
2546
2550
php_stream_filter * filter ;
2547
2551
php_serialize_data_t metadata_hash ;
2548
2552
smart_str main_metadata_str = {0 };
@@ -2568,11 +2572,11 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
2568
2572
zend_hash_clean (& phar -> virtual_dirs );
2569
2573
2570
2574
if (phar -> is_zip ) {
2571
- return phar_zip_flush (phar , user_stub , len , convert , error );
2575
+ return phar_zip_flush (phar , user_stub , is_default_stub , error );
2572
2576
}
2573
2577
2574
2578
if (phar -> is_tar ) {
2575
- return phar_tar_flush (phar , user_stub , len , convert , error );
2579
+ return phar_tar_flush (phar , user_stub , is_default_stub , error );
2576
2580
}
2577
2581
2578
2582
if (PHAR_G (readonly )) {
@@ -2599,75 +2603,37 @@ int phar_flush(phar_archive_data *phar, char *user_stub, zend_long len, int conv
2599
2603
}
2600
2604
2601
2605
if (user_stub ) {
2602
- zend_string * suser_stub ;
2603
- bool free_user_stub = false;
2604
-
2605
- if (len < 0 ) {
2606
- /* resource passed in */
2607
- if (!(php_stream_from_zval_no_verify (stubfile , (zval * )user_stub ))) {
2608
- if (closeoldfile ) {
2609
- php_stream_close (oldfile );
2610
- }
2611
- php_stream_close (newfile );
2612
- if (error ) {
2613
- spprintf (error , 0 , "unable to access resource to copy stub to new phar \"%s\"" , phar -> fname );
2614
- }
2615
- return EOF ;
2616
- }
2617
- if (len == -1 ) {
2618
- len = PHP_STREAM_COPY_ALL ;
2619
- } else {
2620
- len = - len ;
2621
- }
2622
- user_stub = 0 ;
2623
-
2624
- if (!(suser_stub = php_stream_copy_to_mem (stubfile , len , 0 ))) {
2625
- if (closeoldfile ) {
2626
- php_stream_close (oldfile );
2627
- }
2628
- php_stream_close (newfile );
2629
- if (error ) {
2630
- spprintf (error , 0 , "unable to read resource to copy stub to new phar \"%s\"" , phar -> fname );
2631
- }
2632
- return EOF ;
2633
- }
2634
- free_user_stub = true;
2635
- user_stub = ZSTR_VAL (suser_stub );
2636
- len = ZSTR_LEN (suser_stub );
2637
- }
2606
+ char * pos = php_stristr (ZSTR_VAL (user_stub ), halt_stub , ZSTR_LEN (user_stub ), strlen (halt_stub ));
2638
2607
2639
- if (( pos = php_stristr ( user_stub , halt_stub , len , sizeof ( halt_stub ) - 1 )) == NULL ) {
2608
+ if (pos == NULL ) {
2640
2609
if (closeoldfile ) {
2641
2610
php_stream_close (oldfile );
2642
2611
}
2643
2612
php_stream_close (newfile );
2644
2613
if (error ) {
2645
2614
spprintf (error , 0 , "illegal stub for phar \"%s\" (__HALT_COMPILER(); is missing)" , phar -> fname );
2646
2615
}
2647
- if (free_user_stub ) {
2648
- zend_string_free (suser_stub );
2649
- }
2650
2616
return EOF ;
2651
2617
}
2652
- len = pos - user_stub + 18 ;
2653
- if ((size_t )len != php_stream_write (newfile , user_stub , len )
2654
- || 5 != php_stream_write (newfile , " ?>\r\n" , 5 )) {
2618
+
2619
+ size_t len = pos - ZSTR_VAL (user_stub ) + strlen (halt_stub );
2620
+ const char end_sequence [] = " ?>\r\n" ;
2621
+ size_t end_sequence_len = strlen (end_sequence );
2622
+
2623
+ if (
2624
+ len != php_stream_write (newfile , ZSTR_VAL (user_stub ), len )
2625
+ || end_sequence_len != php_stream_write (newfile , end_sequence , end_sequence_len )
2626
+ ) {
2655
2627
if (closeoldfile ) {
2656
2628
php_stream_close (oldfile );
2657
2629
}
2658
2630
php_stream_close (newfile );
2659
2631
if (error ) {
2660
2632
spprintf (error , 0 , "unable to create stub from string in new phar \"%s\"" , phar -> fname );
2661
2633
}
2662
- if (free_user_stub ) {
2663
- zend_string_free (suser_stub );
2664
- }
2665
2634
return EOF ;
2666
2635
}
2667
- phar -> halt_offset = len + 5 ;
2668
- if (free_user_stub ) {
2669
- zend_string_free (suser_stub );
2670
- }
2636
+ phar -> halt_offset = len + end_sequence_len ;
2671
2637
} else {
2672
2638
size_t written ;
2673
2639
0 commit comments