Skip to content

Fix #75102: PharData says invalid checksum for valid tar #6479

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
9 changes: 9 additions & 0 deletions ext/phar/tar.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,15 @@ int phar_parse_tarfile(php_stream* fp, char *fname, size_t fname_len, char *alia
memset(hdr->checksum, ' ', sizeof(hdr->checksum));
sum2 = phar_tar_checksum(buf, old?sizeof(old_tar_header):sizeof(tar_header));

if (old && sum2 != sum1) {
uint32_t sum3 = phar_tar_checksum(buf, sizeof(tar_header));
if (sum3 == sum1) {
/* apparently a broken tar which is in ustar format w/o setting the ustar marker */
sum2 = sum3;
old = 0;
}
}

size = entry.uncompressed_filesize = entry.compressed_filesize =
phar_tar_number(hdr->size, sizeof(hdr->size));

Expand Down
13 changes: 13 additions & 0 deletions ext/phar/tests/bug75102.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--TEST--
Bug #75102 (`PharData` says invalid checksum for valid tar)
--SKIPIF--
<?php
if (!extension_loaded('phar')) die('skip phar extension not available');
?>
--FILE--
<?php
$phar = new PharData(__DIR__ . '/bug75102.tar');
var_dump(file_get_contents($phar['test.txt']->getPathName()));
?>
--EXPECT--
string(9) "yada yada"
Binary file added ext/phar/tests/bug75102.tar
Binary file not shown.