Skip to content
Open
Changes from 1 commit
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
Prev Previous commit
add test
  • Loading branch information
devnexen committed May 8, 2026
commit d852b2f2e20679515e64ed4086808c368ef60ed9
43 changes: 43 additions & 0 deletions ext/phar/tests/tar/gh21986.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
--TEST--
GH-21986 (PharData::getContent() crash on circular symlink chain in tar)
--EXTENSIONS--
phar
--FILE--
<?php
function tar_symlink($name, $target) {
$h = str_pad($name, 100, "\0");
$h .= "0000777\0";
$h .= "0000000\0";
$h .= "0000000\0";
$h .= "00000000000\0";
$h .= "00000000000\0";
$h .= str_repeat(' ', 8);
$h .= '2';
$h .= str_pad($target, 100, "\0");
$h .= "ustar\0" . "00";
$h = str_pad($h, 512, "\0");

$sum = 0;
for ($i = 0; $i < 512; $i++) {
$sum += ord($h[$i]);
}
return substr_replace($h, sprintf("%06o\0 ", $sum), 148, 8);
}

$tar = __DIR__ . '/gh21986.tar';
file_put_contents(
$tar,
tar_symlink('a.txt', 'b.txt') .
tar_symlink('b.txt', 'a.txt') .
str_repeat("\0", 1024)
);

$phar = new PharData($tar);
var_dump($phar['a.txt']->getContent());
?>
--CLEAN--
<?php
@unlink(__DIR__ . '/gh21986.tar');
?>
--EXPECT--
string(0) ""
Loading