xref: /PHP-7.4/ext/phar/tests/tar/bignames.phpt (revision 26dfce7f)
1--TEST--
2Phar: tar with huge filenames
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.require_hash=0
7--FILE--
8<?php
9$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.tar';
10$fname2 = __DIR__ . '/' . basename(__FILE__, '.php') . '.2.tar';
11$fname3 = __DIR__ . '/' . basename(__FILE__, '.php') . '.3.tar';
12$fname4 = __DIR__ . '/' . basename(__FILE__, '.php') . '.4.tar';
13$pname = 'phar://' . $fname;
14
15$p1 = new PharData($fname);
16$p1[str_repeat('a', 100) . '/b'] = 'hi';
17$p1[str_repeat('a', 155) . '/' . str_repeat('b', 100)] = 'hi2';
18copy($fname, $fname2);
19$p2 = new PharData($fname2);
20echo $p2[str_repeat('a', 100) . '/b']->getContent() . "\n";
21echo $p2[str_repeat('a', 155) . '/' . str_repeat('b', 100)]->getContent() . "\n";
22
23try {
24	$p2[str_repeat('a', 400)] = 'yuck';
25} catch (Exception $e) {
26	echo $e->getMessage() . "\n";
27}
28
29try {
30	$p2 = new PharData($fname3);
31	$p2[str_repeat('a', 101)] = 'yuck';
32} catch (Exception $e) {
33	echo $e->getMessage() . "\n";
34}
35
36try {
37	$p2 = new PharData($fname4);
38	$p2[str_repeat('b', 160) . '/' . str_repeat('a', 90)] = 'yuck';
39} catch (Exception $e) {
40	echo $e->getMessage() . "\n";
41}
42?>
43===DONE===
44--CLEAN--
45<?php
46unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.tar');
47unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.2.tar');
48@unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.3.tar');
49@unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.4.tar');
50?>
51--EXPECTF--
52hi
53hi2
54tar-based phar "%sbignames.2.tar" cannot be created, filename "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is too long for tar file format
55tar-based phar "%sbignames.3.tar" cannot be created, filename "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is too long for tar file format
56tar-based phar "%sbignames.4.tar" cannot be created, filename "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" is too long for tar file format
57===DONE===
58