php / php/php-src

Phar Class decompressFiles() bad in PHP 7.4 and 8.x branches

Open
#8,469 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Extension: phar Status: Verified
Dominant language
C
Stars
40.4k
Forks
8.1k
Avg merge
2d 13h
Merged PRs (30d)
96

Description

Description

The following code:

...

<?php
$p = new Phar('/home/gearond/my.phar', FilesystemIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS, 'my.phar');
$p['myfile.txt'] = 'four score and seven years ago our fathers.';
$p['myfile2.txt'] = 'four score and severn years ago our mothers.';
foreach ($p as $file) {
    var_dump($file->getFileName());
    var_dump($file->isCompressed());
    var_dump($file->isCompressed(Phar::BZ2));
    var_dump($file->isCompressed(Phar::GZ));
}
var_dump($p->getSupportedCompression() );
var_dump( $p->compressFiles(Phar::GZ) );
foreach ($p as $file) {
    var_dump($file->getFileName());
    var_dump($file->isCompressed());
    var_dump($file->isCompressed(Phar::BZ2));
    var_dump($file->isCompressed(Phar::GZ));
}
var_dump( $p->decompressFiles() );
foreach ($p as $file) {
    var_dump($file->getFileName());
    var_dump($file->isCompressed());
    var_dump($file->isCompressed(Phar::BZ2));
    var_dump($file->isCompressed(Phar::GZ));
}
var_dump( $p->extractTo("/home/gearond/Project/exploration", null, true) );
?>

Resulted in this output:

string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
array(1) {
  [0]=>
  string(2) "GZ"
}
NULL
string(10) "myfile.txt"
bool(true)
bool(false)
bool(true)
string(11) "myfile2.txt"
bool(true)
bool(false)
bool(true)
bool(true)
string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
bool(true)

gearond@gearond-XPS-15-9570:~/Project/exploration$ cat *.txt
K�/-R(N�/JUH�KQ(N-K-�S�LM,*VHL�WI��d��K�/-R(N�/JUH�KQ(N-K�S�LM,*VHL�Wɦ%�d��gearond@gearond-XPS-15-9570:~/Project/exploration$ 

But I expected this output instead:

string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
array(1) {
  [0]=>
  string(2) "GZ"
}
NULL
string(10) "myfile.txt"
bool(true)
bool(false)
bool(true)
string(11) "myfile2.txt"
bool(true)
bool(false)
bool(true)
bool(true)
string(10) "myfile.txt"
bool(false)
bool(false)
bool(false)
string(11) "myfile2.txt"
bool(false)
bool(false)
bool(false)
bool(true)
gearond@gearond-XPS-15-9570:~/Project/exploration$ cat *.txt
cat *.txt
four score and severn years ago our mothers.four score and seven years ago our fathers.gearond@gearond-XPS-15-9570:~/Project/exploration$


### PHP Version

php 8.1.2 and 7.4

### Operating System

ubuntu 20.04 and 22.04

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Phar::compressFiles() and Phar::decompressFiles() reproduction on PHP 7.4 or 8.x, then trace the Phar implementation and its tests. Done means decompressFiles() leaves extracted files containing their original text rather than compressed bytes.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, php
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.