ext/phar: improve .phar madic directory preservation logic in phar::addEmptyDir()#22011
Open
LamentXU123 wants to merge 1 commit into
Open
ext/phar: improve .phar madic directory preservation logic in phar::addEmptyDir()#22011LamentXU123 wants to merge 1 commit into
LamentXU123 wants to merge 1 commit into
Conversation
LamentXU123
commented
May 11, 2026
| ) { | ||
| size_t prefix_len = (ZSTR_VAL(dir_name)[0] == '/') + sizeof(".phar") - 1; | ||
| char next_char = ZSTR_VAL(dir_name)[prefix_len]; | ||
| if (next_char == '/' || next_char == '\\' || next_char == '\0') { |
Contributor
Author
There was a problem hiding this comment.
Not sure about the \0 logic here.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Now, the .phar directory is a magic dir for phar files, and in phar::addEmptyDir(), users couldn't create a dir naming .phar
The implementation is:
This has two bugs.
Firstly, people can use /.phar to create the .phar dir. The leading / will be ignored. (no need to concern about ../ though, it will be ignored.)
Will return true, while if the dir is .phar it will raise an error.
Secondly, it only matches the prefix. That said, /.pharxxx will not be allowed to create, which is not a magic dir.
This will raise an error.
This PR fix both by 1. adding a trailing check of the path to make .pharx valid 2. adding a check to /.phar
cc @Girgias Thanks!