Skip to content
Permalink
Browse files

Fixed bugs #71317 and #71504

If there are duplicate filenames in tar, the last one wins.
  • Loading branch information...
zghosts authored and nikic committed Feb 2, 2016
1 parent d78220f commit 50b4cafd286eb9d96d71df04e8dc46d321d420b5
2 NEWS
@@ -17,6 +17,8 @@ PHP NEWS
- Phar:
. Fixed bug #71625 (Crash in php7.dll with bad phar filename).
(Anatol)
. Fixed bug #71504 (Parsing of tar file with duplicate filenames causes
memory leak). (Jos Elstgeest)

03 Mar 2016, PHP 5.6.19

@@ -500,7 +500,9 @@ int phar_parse_tarfile(php_stream* fp, char *fname, int fname_len, char *alias,
entry.link = estrndup(hdr->linkname, linkname_len);
}
phar_set_inode(&entry TSRMLS_CC);
zend_hash_add(&myphar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), (void **) &newentry);

zend_hash_update(&myphar->manifest, entry.filename, entry.filename_len, (void*)&entry, sizeof(phar_entry_info), (void **) &newentry);
ZEND_ASSERT(newentry != NULL);

if (entry.is_persistent) {
++entry.manifest_pos;
@@ -0,0 +1,50 @@
--TEST--
Bug #71317: regression in opening tar based phar files
--SKIPIF--
<?php if (!extension_loaded('phar')) die('skip'); ?>
<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
--FILE--
<?php
include dirname(__FILE__) . '/files/tarmaker.php.inc';
$testDirectory = __DIR__ . '/files/test_bug71317';
$testTarFilename = __DIR__ . '/files/test_bug71317.tar';
$tar = new tarmaker($testTarFilename, 'none');
$tar->init();
$tar->addFile('file1.txt', 'file1');
$tar->addFile('file2.txt', 'file2');
$tar->addFile('file3.txt', 'file3');
$tar->addFile('file4.txt', 'file4');
$tar->addFile('file5.txt', 'file5');
$tar->addFile('file2.txt', 'file2a');
$tar->close();
$fname = str_replace('\\', '/', $testTarFilename);
try {
mkdir($testDirectory);
$tar = new PharData($fname);
$tar->extractTo($testDirectory);
$fileContent = file_get_contents($testDirectory . '/file2.txt');
$expectedContent = 'file2a';
if ($fileContent !== $expectedContent) {
throw new Exception(sprintf('Contents of file2.txt ("%s") is invalid, expected "%s"', $fileContent, $expectedContent));
}
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
?>
===DONE===
--CLEAN--
<?php
$testDirectory = __DIR__ . '/files/test_bug71317';
$testTarFilename = __DIR__ . '/files/test_bug71317.tar';
unlink($testTarFilename);
array_map('unlink', glob($testDirectory . "/*.txt"));
rmdir($testDirectory);
?>
--EXPECT--
===DONE===
@@ -0,0 +1,18 @@
--TEST--
Bug #71504: Parsing of tar file with duplicate filenames causes memory leak
--SKIPIF--
<?php if (!extension_loaded('phar')) die('skip'); ?>
<?php if (!extension_loaded("spl")) die("skip SPL not available"); ?>
<?php if (!extension_loaded("zlib")) die("skip zlib not available"); ?>
--FILE--
<?php
$fname = str_replace('\\', '/', dirname(__FILE__) . '/files/HTML_CSS-1.5.4.tgz');
try {
$tar = new PharData($fname);
} catch(Exception $e) {
echo $e->getMessage() . "\n";
}
?>
===DONE===
--EXPECT--
===DONE===
Binary file not shown.

0 comments on commit 50b4caf

Please sign in to comment.
You can’t perform that action at this time.