-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #69279: Compressed ZIP Phar extractTo() creates garbage files
When extracting compressed files from an uncompressed Phar, we must not use the direct file pointer, but rather get an uncompressed file pointer. We also add a test to show that deflated and stored entries are properly extracted. This also fixes #79912, which appears to be a duplicate of #69279. Co-authored-by: Anna Filina <afilina@gmail.com> Closes GH-6599.
- Loading branch information
Showing
6 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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,29 @@ | ||
--TEST-- | ||
Bug #69279 (Compressed ZIP Phar extractTo() creates garbage files) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('phar')) die('skip phar extension not available'); | ||
?> | ||
--INI-- | ||
phar.readonly=0 | ||
--FILE-- | ||
<?php | ||
$w = new Phar(__DIR__ . "/bug69279.phar.zip"); | ||
$w["bug69279.txt"] = "Sample content."; | ||
$w->compressFiles(Phar::GZ); | ||
unset($w); | ||
|
||
$r = new Phar(__DIR__ . "/bug69279.phar.zip"); | ||
var_dump($r["bug69279.txt"]->isCompressed()); | ||
|
||
$r->extractTo(__DIR__, NULL, TRUE); | ||
var_dump(file_get_contents(__DIR__ . "/bug69279.txt")); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
string(15) "Sample content." | ||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__ . "/bug69279.txt"); | ||
@unlink(__DIR__ . "/bug69279.phar.zip"); | ||
?> |
This file contains 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,26 @@ | ||
--TEST-- | ||
Bug #69279 (Compressed ZIP Phar extractTo() creates garbage files) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('phar')) die('skip phar extension not available'); | ||
?> | ||
--FILE-- | ||
<?php | ||
$phar = new PharData(__DIR__ . '/bug69279a.zip'); | ||
mkdir(__DIR__ . '/bug69279a'); | ||
var_dump($phar->extractTo(__DIR__ . '/bug69279a', null, true)); | ||
var_dump(strncmp(file_get_contents(__DIR__ . '/bug69279a/1.txt'), 'Lorem ipsum', 11)); | ||
var_dump(strncmp(file_get_contents(__DIR__ . '/bug69279a/2.txt'), 'foo', 3)); | ||
var_dump(strncmp(file_get_contents(__DIR__ . '/bug69279a/3.txt'), 'Lorem ipsum', 11)); | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
int(0) | ||
int(0) | ||
int(0) | ||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__ . '/bug69279a/1.txt'); | ||
@unlink(__DIR__ . '/bug69279a/2.txt'); | ||
@unlink(__DIR__ . '/bug69279a/3.txt'); | ||
@rmdir(__DIR__ . '/bug69279a'); |
Binary file not shown.
This file contains 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,35 @@ | ||
--TEST-- | ||
Bug #79912 (Phar::decompressFiles not working) | ||
--SKIPIF-- | ||
<?php | ||
if (!extension_loaded('phar')) die('skip phar extension is not available'); | ||
?> | ||
--INI-- | ||
phar.readonly=0 | ||
--FILE-- | ||
<?php | ||
$phar = new Phar(__DIR__ . "/bug79912.phar"); | ||
$phar->addFromString("test.txt", "This is a test file.This is a test file.This is a test file."); | ||
$file = $phar["test.txt"]; | ||
var_dump($file->compress(Phar::GZ)); //true (success) | ||
var_dump($file->getContent()); | ||
var_dump($file->isCompressed()); //true (the file is compressed) | ||
var_dump($phar->decompressFiles()); //true (success) | ||
var_dump($file->isCompressed()); //false (the file should not be compressed anymore) | ||
var_dump($phar->extractTo(__DIR__ . "/bug79912")); //true | ||
var_dump(file_get_contents(__DIR__ . "/bug79912/test.txt")); //the extracted file in the folder should be decompressed | ||
?> | ||
--EXPECT-- | ||
bool(true) | ||
string(60) "This is a test file.This is a test file.This is a test file." | ||
bool(true) | ||
bool(true) | ||
bool(false) | ||
bool(true) | ||
string(60) "This is a test file.This is a test file.This is a test file." | ||
--CLEAN-- | ||
<?php | ||
@unlink(__DIR__ . "/bug79912/test.txt"); | ||
@rmdir(__DIR__ . "/bug79912"); | ||
@unlink(__DIR__ . "/bug79912.phar"); | ||
?> |