@@ -1612,7 +1612,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
16121612 return ZEND_HASH_APPLY_STOP ;
16131613 }
16141614after_open_fp :
1615- if (str_key_len >= sizeof ( ".phar" ) - 1 && ! memcmp ( str_key , ".phar" , sizeof ( ".phar" ) - 1 )) {
1615+ if (phar_path_is_magic_phar_ex ( str_key , str_key_len )) {
16161616 /* silently skip any files that would be added to the magic .phar directory */
16171617 if (save ) {
16181618 efree (save );
@@ -3401,14 +3401,14 @@ PHP_METHOD(Phar, copy)
34013401 RETURN_THROWS ();
34023402 }
34033403
3404- if (zend_string_starts_with_literal (old_file , ".phar" )) {
3404+ if (phar_is_magic_phar (old_file )) {
34053405 /* can't copy a meta file */
34063406 zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
34073407 "file \"%s\" cannot be copied to file \"%s\", cannot copy Phar meta-file in %s" , ZSTR_VAL (old_file ), ZSTR_VAL (new_file ), ZSTR_VAL (phar_obj -> archive -> fname ));
34083408 RETURN_THROWS ();
34093409 }
34103410
3411- if (zend_string_starts_with_literal (new_file , ".phar" )) {
3411+ if (phar_is_magic_phar (new_file )) {
34123412 /* can't copy a meta file */
34133413 zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
34143414 "file \"%s\" cannot be copied to file \"%s\", cannot copy to Phar meta-file in %s" , ZSTR_VAL (old_file ), ZSTR_VAL (new_file ), ZSTR_VAL (phar_obj -> archive -> fname ));
@@ -3495,7 +3495,7 @@ PHP_METHOD(Phar, offsetExists)
34953495 }
34963496
34973497 /* none of these are real files, so they don't exist */
3498- RETURN_BOOL (!zend_string_starts_with_literal (file_name , ".phar" ));
3498+ RETURN_BOOL (!phar_is_magic_phar (file_name ));
34993499 } else {
35003500 /* If the info class is not based on PharFileInfo, directories are not directly instantiable */
35013501 if (UNEXPECTED (!instanceof_function (phar_obj -> spl .info_class , phar_ce_entry ))) {
@@ -3538,7 +3538,7 @@ PHP_METHOD(Phar, offsetGet)
35383538 RETURN_THROWS ();
35393539 }
35403540
3541- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3541+ if (phar_is_magic_phar (file_name )) {
35423542 zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot directly get any files or directories in magic \".phar\" directory" );
35433543 RETURN_THROWS ();
35443544 }
@@ -3568,16 +3568,9 @@ static void phar_add_file(phar_archive_data **pphar, zend_string *file_name, con
35683568 ALLOCA_FLAG (filename_use_heap )
35693569#endif
35703570
3571- if (
3572- zend_string_starts_with_literal (file_name , ".phar" )
3573- || zend_string_starts_with_literal (file_name , "/.phar" )
3574- ) {
3575- size_t prefix_len = (ZSTR_VAL (file_name )[0 ] == '/' ) + sizeof (".phar" )- 1 ;
3576- char next_char = ZSTR_VAL (file_name )[prefix_len ];
3577- if (next_char == '/' || next_char == '\\' || next_char == '\0' ) {
3578- zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create any files in magic \".phar\" directory" );
3579- return ;
3580- }
3571+ if (phar_is_magic_phar (file_name )) {
3572+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create any files in magic \".phar\" directory" );
3573+ return ;
35813574 }
35823575
35833576 /* TODO How to handle Windows path normalisation with zend_string ? */
@@ -3722,7 +3715,7 @@ PHP_METHOD(Phar, offsetSet)
37223715 RETURN_THROWS ();
37233716 }
37243717
3725- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3718+ if (phar_is_magic_phar (file_name )) {
37263719 zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot set any files or directories in magic \".phar\" directory" );
37273720 RETURN_THROWS ();
37283721 }
@@ -3789,16 +3782,9 @@ PHP_METHOD(Phar, addEmptyDir)
37893782
37903783 PHAR_ARCHIVE_OBJECT ();
37913784
3792- if (
3793- zend_string_starts_with_literal (dir_name , ".phar" )
3794- || zend_string_starts_with_literal (dir_name , "/.phar" )
3795- ) {
3796- size_t prefix_len = (ZSTR_VAL (dir_name )[0 ] == '/' ) + sizeof (".phar" ) - 1 ;
3797- char next_char = ZSTR_VAL (dir_name )[prefix_len ];
3798- if (next_char == '/' || next_char == '\\' || next_char == '\0' ) {
3799- zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create a directory in magic \".phar\" directory" );
3800- RETURN_THROWS ();
3801- }
3785+ if (phar_is_magic_phar (dir_name )) {
3786+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create a directory in magic \".phar\" directory" );
3787+ RETURN_THROWS ();
38023788 }
38033789
38043790 phar_mkdir (& phar_obj -> archive , dir_name );
@@ -4099,7 +4085,7 @@ ZEND_ATTRIBUTE_NONNULL static zend_result phar_extract_file(bool overwrite, phar
40994085 return SUCCESS ;
41004086 }
41014087
4102- if (zend_string_starts_with_literal (entry -> filename , ".phar" )) {
4088+ if (phar_is_magic_phar (entry -> filename )) {
41034089 return SUCCESS ;
41044090 }
41054091 /* strip .. from path and restrict it to be under dest directory */
0 commit comments