@@ -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 );
@@ -3562,11 +3562,8 @@ PHP_METHOD(Phar, offsetExists)
35623562 }
35633563 }
35643564
3565- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3566- /* none of these are real files, so they don't exist */
3567- RETURN_FALSE ;
3568- }
3569- RETURN_TRUE ;
3565+ /* none of these are real files, so they don't exist */
3566+ RETURN_BOOL (!phar_is_magic_phar (file_name ));
35703567 } else {
35713568 /* If the info class is not based on PharFileInfo, directories are not directly instantiable */
35723569 if (UNEXPECTED (!instanceof_function (phar_obj -> spl .info_class , phar_ce_entry ))) {
@@ -3609,7 +3606,7 @@ PHP_METHOD(Phar, offsetGet)
36093606 RETURN_THROWS ();
36103607 }
36113608
3612- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3609+ if (phar_is_magic_phar (file_name )) {
36133610 zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot directly get any files or directories in magic \".phar\" directory" );
36143611 RETURN_THROWS ();
36153612 }
@@ -3640,16 +3637,9 @@ static void phar_add_file(phar_archive_data **pphar, zend_string *file_name, con
36403637 ALLOCA_FLAG (filename_use_heap )
36413638#endif
36423639
3643- if (
3644- zend_string_starts_with_literal (file_name , ".phar" )
3645- || zend_string_starts_with_literal (file_name , "/.phar" )
3646- ) {
3647- size_t prefix_len = (ZSTR_VAL (file_name )[0 ] == '/' ) + sizeof (".phar" )- 1 ;
3648- char next_char = ZSTR_VAL (file_name )[prefix_len ];
3649- if (next_char == '/' || next_char == '\\' || next_char == '\0' ) {
3650- zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create any files in magic \".phar\" directory" );
3651- return ;
3652- }
3640+ if (phar_is_magic_phar (file_name )) {
3641+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create any files in magic \".phar\" directory" );
3642+ return ;
36533643 }
36543644
36553645 /* TODO How to handle Windows path normalisation with zend_string ? */
@@ -3796,7 +3786,7 @@ PHP_METHOD(Phar, offsetSet)
37963786 RETURN_THROWS ();
37973787 }
37983788
3799- if (zend_string_starts_with_literal (file_name , ".phar" )) {
3789+ if (phar_is_magic_phar (file_name )) {
38003790 zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot set any files or directories in magic \".phar\" directory" );
38013791 RETURN_THROWS ();
38023792 }
@@ -3863,16 +3853,9 @@ PHP_METHOD(Phar, addEmptyDir)
38633853
38643854 PHAR_ARCHIVE_OBJECT ();
38653855
3866- if (
3867- zend_string_starts_with_literal (dir_name , ".phar" )
3868- || zend_string_starts_with_literal (dir_name , "/.phar" )
3869- ) {
3870- size_t prefix_len = (ZSTR_VAL (dir_name )[0 ] == '/' ) + sizeof (".phar" )- 1 ;
3871- char next_char = ZSTR_VAL (dir_name )[prefix_len ];
3872- if (next_char == '/' || next_char == '\\' || next_char == '\0' ) {
3873- zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create a directory in magic \".phar\" directory" );
3874- RETURN_THROWS ();
3875- }
3856+ if (phar_is_magic_phar (dir_name )) {
3857+ zend_throw_exception_ex (spl_ce_BadMethodCallException , 0 , "Cannot create a directory in magic \".phar\" directory" );
3858+ RETURN_THROWS ();
38763859 }
38773860
38783861 phar_mkdir (& phar_obj -> archive , dir_name );
@@ -4178,7 +4161,7 @@ static zend_result phar_extract_file(bool overwrite, phar_entry_info *entry, cha
41784161 return SUCCESS ;
41794162 }
41804163
4181- if (entry -> filename_len >= sizeof ( ".phar" ) - 1 && ! memcmp ( entry -> filename , ".phar" , sizeof ( ".phar" ) - 1 )) {
4164+ if (phar_path_is_magic_phar_ex ( entry -> filename , entry -> filename_len )) {
41824165 return SUCCESS ;
41834166 }
41844167 /* strip .. from path and restrict it to be under dest directory */
0 commit comments