Skip to content

Commit e197f65

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #76584: PharFileInfo::decompress not working
2 parents 412b476 + 136f51f commit e197f65

File tree

3 files changed

+56
-5
lines changed

3 files changed

+56
-5
lines changed

NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ PHP NEWS
3737
- OpenSSL:
3838
. Fixed bug #79145 (openssl memory leak). (cmb, Nikita)
3939

40+
- Phar:
41+
. Fixed bug #76584 (PharFileInfo::decompress not working). (cmb)
42+
4043
- Reflection:
4144
. Fixed bug #79115 (ReflectionClass::isCloneable call reflected class
4245
__destruct). (Nikita)

ext/phar/phar_object.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5042,6 +5042,7 @@ PHP_METHOD(PharFileInfo, compress)
50425042
PHP_METHOD(PharFileInfo, decompress)
50435043
{
50445044
char *error;
5045+
char *compression_type;
50455046
PHAR_ENTRY_OBJECT();
50465047

50475048
if (zend_parse_parameters_none() == FAILURE) {
@@ -5092,12 +5093,24 @@ PHP_METHOD(PharFileInfo, decompress)
50925093
/* re-populate after copy-on-write */
50935094
entry_obj->entry = zend_hash_str_find_ptr(&phar->manifest, entry_obj->entry->filename, entry_obj->entry->filename_len);
50945095
}
5095-
if (!entry_obj->entry->fp) {
5096-
if (FAILURE == phar_open_archive_fp(entry_obj->entry->phar)) {
5097-
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0, "Cannot decompress entry \"%s\", phar error: Cannot open phar archive \"%s\" for reading", entry_obj->entry->filename, entry_obj->entry->phar->fname);
5096+
switch (entry_obj->entry->flags & PHAR_ENT_COMPRESSION_MASK) {
5097+
case PHAR_ENT_COMPRESSED_GZ:
5098+
compression_type = "gzip";
5099+
break;
5100+
case PHAR_ENT_COMPRESSED_BZ2:
5101+
compression_type = "bz2";
5102+
break;
5103+
default:
5104+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
5105+
"Cannot decompress file compressed with unknown compression type");
50985106
return;
5099-
}
5100-
entry_obj->entry->fp_type = PHAR_FP;
5107+
}
5108+
/* decompress this file indirectly */
5109+
if (SUCCESS != phar_open_entry_fp(entry_obj->entry, &error, 1)) {
5110+
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
5111+
"Phar error: Cannot decompress %s-compressed file \"%s\" in phar \"%s\": %s", compression_type, entry_obj->entry->filename, entry_obj->entry->phar->fname, error);
5112+
efree(error);
5113+
return;
51015114
}
51025115

51035116
entry_obj->entry->old_flags = entry_obj->entry->flags;

ext/phar/tests/bug76584.phpt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
Bug #76584 (PharFileInfo::decompress not working)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('phar')) die('skip phar extension not available');
6+
if (!extension_loaded('zlib')) die('skip zlib extension not available');
7+
?>
8+
--INI--
9+
phar.readonly=0
10+
--FILE--
11+
<?php
12+
$phar = new Phar(__DIR__ . '/76584.phar');
13+
$phar->addFromString('76584.txt', 'This is a test file.');
14+
$file = $phar['76584.txt'];
15+
var_dump($file->compress(Phar::GZ));
16+
var_dump($file->isCompressed());
17+
var_dump($file->decompress());
18+
var_dump($file->isCompressed());
19+
mkdir(__DIR__ . '/76584');
20+
var_dump($phar->extractTo(__DIR__ . '/76584'));
21+
echo file_get_contents(__DIR__ . '/76584/76584.txt');
22+
?>
23+
--EXPECT--
24+
bool(true)
25+
bool(true)
26+
bool(true)
27+
bool(false)
28+
bool(true)
29+
This is a test file.
30+
--CLEAN--
31+
<?php
32+
unlink(__DIR__ . '/76584/76584.txt');
33+
rmdir(__DIR__ . '/76584');
34+
unlink(__DIR__ . '/76584.phar');
35+
?>

0 commit comments

Comments
 (0)