Skip to content

Fix GH-16406: Assertion failure in ext/phar/phar.c:2808 #16470

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/phar/phar_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,9 @@ static zend_object *phar_convert_to_other(phar_archive_data *source, int convert
newentry.tar_type = (entry->is_dir ? TAR_DIR : TAR_FILE);
}

/* The header offset is only used for unmodified zips.
* Once modified, phar_zip_changed_apply_int() will update the header_offset. */
newentry.header_offset = 0;
newentry.is_modified = 1;
newentry.phar = phar;
newentry.old_flags = newentry.flags & ~PHAR_ENT_COMPRESSION_MASK; /* remove compression from old_flags */
Expand Down
35 changes: 35 additions & 0 deletions ext/phar/tests/gh16406.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--TEST--
GH-16406 (Assertion failure in ext/phar/phar.c:2808)
--EXTENSIONS--
phar
zlib
--INI--
phar.readonly=0
phar.require_hash=0
--FILE--
<?php
$fname = __DIR__ . '/gh16406.phar';
@unlink($fname . '.tar');
@unlink($fname . '.gz');
@unlink($fname);
Comment on lines +12 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't be required, but won't hurt.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the reason I added this is because when I was writing the test I first had messed up the clean section, which meant the test wouldn't execute anymore.

$file = '<?php __HALT_COMPILER(); ?>';
$files['b'] = 'b';
$files['c'] = 'c';
include __DIR__.'/files/phar_test.inc';
$phar = new Phar($fname);
$phar->compressFiles(Phar::GZ);
$phar = $phar->convertToExecutable(Phar::TAR);
$phar = $phar->convertToExecutable(Phar::PHAR, Phar::GZ);
var_dump($phar['b']->openFile()->fread(4096));
var_dump($phar['c']->openFile()->fread(4096));
?>
--CLEAN--
<?php
$fname = __DIR__ . '/gh16406.phar';
@unlink($fname . '.tar');
@unlink($fname . '.gz');
@unlink($fname);
?>
--EXPECT--
string(1) "b"
string(1) "c"
Loading