Skip to content

Commit d852b2f

Browse files
committed
add test
1 parent 1300018 commit d852b2f

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

ext/phar/tests/tar/gh21986.phpt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
--TEST--
2+
GH-21986 (PharData::getContent() crash on circular symlink chain in tar)
3+
--EXTENSIONS--
4+
phar
5+
--FILE--
6+
<?php
7+
function tar_symlink($name, $target) {
8+
$h = str_pad($name, 100, "\0");
9+
$h .= "0000777\0";
10+
$h .= "0000000\0";
11+
$h .= "0000000\0";
12+
$h .= "00000000000\0";
13+
$h .= "00000000000\0";
14+
$h .= str_repeat(' ', 8);
15+
$h .= '2';
16+
$h .= str_pad($target, 100, "\0");
17+
$h .= "ustar\0" . "00";
18+
$h = str_pad($h, 512, "\0");
19+
20+
$sum = 0;
21+
for ($i = 0; $i < 512; $i++) {
22+
$sum += ord($h[$i]);
23+
}
24+
return substr_replace($h, sprintf("%06o\0 ", $sum), 148, 8);
25+
}
26+
27+
$tar = __DIR__ . '/gh21986.tar';
28+
file_put_contents(
29+
$tar,
30+
tar_symlink('a.txt', 'b.txt') .
31+
tar_symlink('b.txt', 'a.txt') .
32+
str_repeat("\0", 1024)
33+
);
34+
35+
$phar = new PharData($tar);
36+
var_dump($phar['a.txt']->getContent());
37+
?>
38+
--CLEAN--
39+
<?php
40+
@unlink(__DIR__ . '/gh21986.tar');
41+
?>
42+
--EXPECT--
43+
string(0) ""

0 commit comments

Comments
 (0)