@@ -1619,7 +1619,7 @@ static int phar_build(zend_object_iterator *iter, void *puser) /* {{{ */
16191619 return ZEND_HASH_APPLY_STOP ;
16201620 }
16211621after_open_fp :
1622- if (str_key_len >= sizeof ( ".phar" ) - 1 && ! memcmp ( str_key , ".phar" , sizeof ( ".phar" ) - 1 )) {
1622+ if (phar_path_is_magic_phar_ex ( str_key , str_key_len )) {
16231623 /* silently skip any files that would be added to the magic .phar directory */
16241624 if (save ) {
16251625 efree (save );
@@ -3468,14 +3468,14 @@ PHP_METHOD(Phar, copy)
34683468 RETURN_THROWS ();
34693469 }
34703470
3471- if (zend_string_starts_with_literal (old_file , ".phar" )) {
3471+ if (phar_is_magic_phar (old_file )) {
34723472 /* can't copy a meta file */
34733473 zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
34743474 "file \"%s\" cannot be copied to file \"%s\", cannot copy Phar meta-file in %s" , ZSTR_VAL (old_file ), ZSTR_VAL (new_file ), phar_obj -> archive -> fname );
34753475 RETURN_THROWS ();
34763476 }
34773477
3478- if (zend_string_starts_with_literal (new_file , ".phar" )) {
3478+ if (phar_is_magic_phar (new_file )) {
34793479 /* can't copy a meta file */
34803480 zend_throw_exception_ex (spl_ce_UnexpectedValueException , 0 ,
34813481 "file \"%s\" cannot be copied to file \"%s\", cannot copy to Phar meta-file in %s" , ZSTR_VAL (old_file ), ZSTR_VAL (new_file ), phar_obj -> archive -> fname );
@@ -3561,11 +3561,8 @@ PHP_METHOD(Phar, offsetExists)
35613561 }
35623562 }
35633563
3564- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3565- /* none of these are real files, so they don't exist */
3566- RETURN_FALSE ;
3567- }
3568- RETURN_TRUE ;
3564+ /* none of these are real files, so they don't exist */
3565+ RETURN_BOOL (!phar_is_magic_phar (file_name ));
35693566 } else {
35703567 /* If the info class is not based on PharFileInfo, directories are not directly instantiable */
35713568 if (UNEXPECTED (!instanceof_function (phar_obj -> spl .info_class , phar_ce_entry ))) {
@@ -3608,7 +3605,7 @@ PHP_METHOD(Phar, offsetGet)
36083605 RETURN_THROWS ();
36093606 }
36103607
3611- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3608+ if (phar_is_magic_phar (file_name )) {
36123609 zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot directly get any files or directories in magic \".phar\" directory" );
36133610 RETURN_THROWS ();
36143611 }
@@ -3639,16 +3636,9 @@ static void phar_add_file(phar_archive_data **pphar, zend_string *file_name, con
36393636 ALLOCA_FLAG (filename_use_heap )
36403637#endif
36413638
3642- if (
3643- zend_string_starts_with_literal (file_name , ".phar" )
3644- || zend_string_starts_with_literal (file_name , "/.phar" )
3645- ) {
3646- size_t prefix_len = (ZSTR_VAL (file_name )[0 ] == '/' ) + sizeof (".phar" )- 1 ;
3647- char next_char = ZSTR_VAL (file_name )[prefix_len ];
3648- if (next_char == '/' || next_char == '\\' || next_char == '\0' ) {
3649- zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create any files in magic \".phar\" directory" );
3650- return ;
3651- }
3639+ if (phar_is_magic_phar (file_name )) {
3640+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create any files in magic \".phar\" directory" );
3641+ return ;
36523642 }
36533643
36543644 /* TODO How to handle Windows path normalisation with zend_string ? */
@@ -3795,7 +3785,7 @@ PHP_METHOD(Phar, offsetSet)
37953785 RETURN_THROWS ();
37963786 }
37973787
3798- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3788+ if (phar_is_magic_phar (file_name )) {
37993789 zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot set any files or directories in magic \".phar\" directory" );
38003790 RETURN_THROWS ();
38013791 }
@@ -3862,16 +3852,9 @@ PHP_METHOD(Phar, addEmptyDir)
38623852
38633853 PHAR_ARCHIVE_OBJECT ();
38643854
3865- if (
3866- zend_string_starts_with_literal (dir_name , ".phar" )
3867- || zend_string_starts_with_literal (dir_name , "/.phar" )
3868- ) {
3869- size_t prefix_len = (ZSTR_VAL (dir_name )[0 ] == '/' ) + sizeof (".phar" )- 1 ;
3870- char next_char = ZSTR_VAL (dir_name )[prefix_len ];
3871- if (next_char == '/' || next_char == '\\' || next_char == '\0' ) {
3872- zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create a directory in magic \".phar\" directory" );
3873- RETURN_THROWS ();
3874- }
3855+ if (phar_is_magic_phar (dir_name )) {
3856+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create a directory in magic \".phar\" directory" );
3857+ RETURN_THROWS ();
38753858 }
38763859
38773860 phar_mkdir (& phar_obj -> archive , dir_name );
@@ -4177,7 +4160,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
41774160 return SUCCESS ;
41784161 }
41794162
4180- if (zend_string_starts_with_literal (entry -> filename , ".phar" )) {
4163+ if (phar_is_magic_phar (entry -> filename )) {
41814164 return SUCCESS ;
41824165 }
41834166 /* strip .. from path and restrict it to be under dest directory */
0 commit comments