@@ -107,11 +107,12 @@ php_stream *phar_get_efp(phar_entry_info *entry, bool follow_links) /* {{{ */
107107 }
108108
109109 if (phar_get_fp_type (entry ) == PHAR_FP ) {
110- if (!phar_get_entrypfp (entry )) {
110+ php_stream * stream = phar_get_entrypfp (entry );
111+ if (!stream ) {
111112 /* re-open just in time for cases where our refcount reached 0 on the phar archive */
112- phar_open_archive_fp (entry -> phar );
113+ stream = phar_open_archive_fp (entry -> phar );
113114 }
114- return phar_get_entrypfp ( entry ) ;
115+ return stream ;
115116 } else if (phar_get_fp_type (entry ) == PHAR_UFP ) {
116117 return phar_get_entrypufp (entry );
117118 } else if (entry -> fp_type == PHAR_MOD ) {
@@ -708,24 +709,23 @@ static inline void phar_set_pharfp(phar_archive_data *phar, php_stream *fp)
708709 PHAR_G (cached_fp )[phar -> phar_pos ].fp = fp ;
709710}
710711
711- /* initialize a phar_archive_data's read-only fp for existing phar data */
712- zend_result phar_open_archive_fp (phar_archive_data * phar ) /* {{{ */
712+ /* Initialize a phar_archive_data's read-only fp for existing phar data.
713+ * The stream is owned by the `phar` object and must not be closed manually. */
714+ php_stream * phar_open_archive_fp (phar_archive_data * phar ) /* {{{ */
713715{
714- if (phar_get_pharfp (phar )) {
715- return SUCCESS ;
716+ php_stream * stream = phar_get_pharfp (phar );
717+ if (stream ) {
718+ return stream ;
716719 }
717720
718721 if (php_check_open_basedir (phar -> fname )) {
719- return FAILURE ;
722+ return NULL ;
720723 }
721724
722- phar_set_pharfp (phar , php_stream_open_wrapper (phar -> fname , "rb" , IGNORE_URL |STREAM_MUST_SEEK |0 , NULL ));
723-
724- if (!phar_get_pharfp (phar )) {
725- return FAILURE ;
726- }
725+ stream = php_stream_open_wrapper (phar -> fname , "rb" , IGNORE_URL |STREAM_MUST_SEEK , NULL );
726+ phar_set_pharfp (phar , stream );
727727
728- return SUCCESS ;
728+ return stream ;
729729}
730730/* }}} */
731731
@@ -829,7 +829,7 @@ ZEND_ATTRIBUTE_NONNULL zend_result phar_open_entry_fp(phar_entry_info *entry, ch
829829 }
830830
831831 if (!phar_get_pharfp (phar )) {
832- if (FAILURE == phar_open_archive_fp (phar )) {
832+ if (! phar_open_archive_fp (phar )) {
833833 spprintf (error , 4096 , "phar error: Cannot open phar archive \"%s\" for reading" , phar -> fname );
834834 return FAILURE ;
835835 }
0 commit comments