|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69279 Compressed ZIP Phar extractTo() creates garbage files
Submitted: 2015-03-23 01:32 UTC Modified: 2020-12-08 16:47 UTC
Avg. Score:3.3 ± 1.4
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:2 (66.7%)
From: mario at include-once dot org Assigned: cmb (profile)
Status: Closed Package: PHAR related
PHP Version: 7.4 OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: mario at include-once dot org
New email:
PHP Version: OS:


 [2015-03-23 01:32 UTC] mario at include-once dot org
See also #50797 - "PHAR fails to extract ZIP archives, but TAR is ok",
which seems to document the same issue.

Phar::extractTo() creates compressed/garbage output. Extracted files match the recorded file sizes. But they'll contain some binary content instead of the actual and decompressed file contents.

It seems extractTo slices out raw ZIP archive contents, 18 bytes after the stored filename of the local PK file header.

This behaviour isn't specific to 5.6.x, happened throughout 5.3, 5.4 and 5.5 too.
(Example run against 5.6.6-1~dotdeb.1/ZTS/amd64.)

An interesting workaround btw, is to use the phar:// streamwrapper prior. If a compressed file from the ZIP is accessed (per file_get_contents("phar://") beforehand), then Phar::extractTo can reproduce the original file content.

Test script:
define('PHAR_FNAME', "");
define('SAMPLE_FN',  "phar-test.txt");
define('SAMPLE_TXT', "Sample content.\n");

// Create ZIP+GZ-Phar
$w = new Phar(PHAR_FNAME);

// Open anew
$r = new Phar(PHAR_FNAME);

// Extract to file and compare to sample: fails
$r->extractTo(".", NULL, TRUE);
assert(SAMPLE_TXT === file_get_contents(SAMPLE_FN));

Expected result:
Example ``


Actual result:
The "Sample content.\n" from `test-phar.txt` gets created as:

 4e0b2dcc49c84855cfce492b2bcde3d1  N�-�IUH��+I�+�


Add a Patch

Pull Requests

Pull requests:

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-02 21:50 UTC]
-Status: Open +Status: Verified
 [2015-08-02 21:53 UTC]
PharData has the same problem (probably the same code) - this code on a zip file:

    $phar = new PharData('');

when contains text files, produces garbage files as a result. Looks like Phar fogets to uncompress the data or something like that.
 [2020-12-08 16:28 UTC]
-Assigned To: +Assigned To: cmb
 [2020-12-08 16:45 UTC]
-PHP Version: 5.6.7 +PHP Version: 7.4
 [2020-12-08 16:47 UTC]
-Operating System: Linux/3.13/amd64 +Operating System: *
 [2021-01-12 14:50 UTC]
The following pull request has been associated:

Patch Name: Fix #69279: Compressed ZIP Phar extractTo() creates garbage files
On GitHub:
 [2021-01-19 09:31 UTC]
Automatic comment on behalf of
Log: Fix #69279: Compressed ZIP Phar extractTo() creates garbage files
 [2021-01-19 09:31 UTC]
-Status: Verified +Status: Closed
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Mar 08 13:01:23 2021 UTC