-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix bug #74154: Phar extractTo creates empty files #20754
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ndossche
wants to merge
1
commit into
php:PHP-8.4
Choose a base branch
from
ndossche:fix-74154
base: PHP-8.4
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+56
−9
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| --TEST-- | ||
| Bug #74154 (Phar extractTo creates empty files) | ||
| --EXTENSIONS-- | ||
| phar | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| $dir = __DIR__.'/bug74154'; | ||
| mkdir($dir); | ||
| file_put_contents("$dir/1.txt", str_repeat('h', 64)); | ||
| file_put_contents("$dir/2.txt", str_repeat('i', 64)); | ||
| $phar = new PharData(__DIR__.'/bug74154.tar'); | ||
| $phar->buildFromDirectory($dir); | ||
|
|
||
| $compPhar = $phar->compress(Phar::GZ); | ||
| unset($phar); //make sure that test.tar is closed | ||
| unlink(__DIR__.'/bug74154.tar'); | ||
| unset($compPhar); //make sure that test.tar.gz is closed | ||
| $extractingPhar = new PharData(__DIR__.'/bug74154.tar.gz'); | ||
| $extractingPhar->extractTo($dir.'_out'); | ||
|
|
||
| var_dump(file_get_contents($dir.'_out/1.txt')); | ||
| var_dump(file_get_contents($dir.'_out/2.txt')); | ||
|
|
||
| ?> | ||
| --CLEAN-- | ||
| <?php | ||
| $dir = __DIR__.'/bug74154'; | ||
| @unlink("$dir/1.txt"); | ||
| @unlink("$dir/2.txt"); | ||
| @rmdir($dir); | ||
| @unlink($dir.'_out/1.txt'); | ||
| @unlink($dir.'_out/2.txt'); | ||
| @rmdir($dir.'_out'); | ||
| @unlink(__DIR__.'/bug74154.tar'); | ||
| @unlink(__DIR__.'/bug74154.tar.gz'); | ||
| ?> | ||
| --EXPECT-- | ||
| string(64) "hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh" | ||
| string(64) "iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii" |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dumb question but why bitwise or assign to a boolean value?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because at this line I want
remove_fname_cacheequal to!zend_hash_num_elements(&phar->manifest) || (phar->flags & PHAR_FILE_COMPRESSION_MASK). The variable was already set to!zend_hash_num_elements(&phar->manifest)so I just need the rhs of the OR. I can choose between a logical OR / bitwise OR. They would yield the same result.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, I never realized that a bitwise or is equivalent to a logical or for booleans.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, not fully equivalent. Logical OR will short-circuit while bitwise OR won't. In this case it doesn't matter.