1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
--TEST--
Phar: Phar::extractTo()
--SKIPIF--
<?php if (!extension_loaded("phar")) die("skip"); ?>
--CONFLICTS--
tempmanifest1.phar.php
--INI--
phar.readonly=0
--FILE--
<?php
$fname = __DIR__ . '/tempmanifest1.phar.php';
$pname = 'phar://' . $fname;
$a = new Phar($fname);
$a['file1.txt'] = 'hi';
$a['file2.txt'] = 'hi2';
$a['subdir/ectory/file.txt'] = 'hi3';
$a->mount($pname . '/mount', __FILE__);
$a->addEmptyDir('one/level');
$a->extractTo(__DIR__ . '/extract', 'mount');
$a->extractTo(__DIR__ . '/extract');
$out = array();
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/extract', 0x00003000), RecursiveIteratorIterator::CHILD_FIRST) as $p => $b) {
$out[] = $p;
}
sort($out);
foreach ($out as $b) {
echo "$b\n";
}
$a->extractTo(__DIR__ . '/extract1', 'file1.txt');
var_dump(file_get_contents(__DIR__ . '/extract1/file1.txt'));
$a->extractTo(__DIR__ . '/extract1', 'subdir/ectory/file.txt');
var_dump(file_get_contents(__DIR__ . '/extract1/subdir/ectory/file.txt'));
$a->extractTo(__DIR__ . '/extract1-2', array('file2.txt', 'one/level'));
var_dump(file_get_contents(__DIR__ . '/extract1-2/file2.txt'));
var_dump(is_dir(__DIR__ . '/extract1-2/one/level'));
try {
$a->extractTo(__DIR__ . '/whatever', new stdClass());
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
$a->extractTo(array());
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
$a->extractTo('');
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
file_put_contents(__DIR__ . '/oops', 'I is file');
try {
$a->extractTo(__DIR__ . '/oops', 'file1.txt');
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
$a->extractTo(__DIR__ . '/oops1', array(array(), 'file1.txt'));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
try {
$a->extractTo(__DIR__ . '/extract', 'file1.txt');
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
file_put_contents(__DIR__ . '/extract/file1.txt', 'first');
var_dump(file_get_contents(__DIR__ . '/extract/file1.txt'));
$a->extractTo(__DIR__ . '/extract', 'file1.txt', true);
var_dump(file_get_contents(__DIR__ . '/extract/file1.txt'));
try {
$a->extractTo(str_repeat('a', 20000), 'file1.txt');
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
$a[str_repeat('a', 20000)] = 'long';
try {
$a->extractTo(__DIR__ . '/extract', str_repeat('a', 20000));
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
?>
--CLEAN--
<?php
@rmdir(__DIR__ . '/whatever');
@unlink(__DIR__ . '/oops');
@rmdir(__DIR__ . '/oops1');
@unlink(__DIR__ . '/tempmanifest1.phar.php');
$e = __DIR__ . '/extract/';
@unlink($e . 'file1.txt');
@unlink($e . 'file2.txt');
@unlink($e . 'subdir/ectory/file.txt');
@rmdir($e . 'subdir/ectory');
@rmdir($e . 'subdir');
@rmdir($e . 'one/level');
@rmdir($e . 'one');
@rmdir($e);
$e = __DIR__ . '/extract1/';
@unlink($e . 'file1.txt');
@unlink($e . 'subdir/ectory/file.txt');
@rmdir($e . 'subdir/ectory');
@rmdir($e . 'subdir');
@rmdir($e);
$e = __DIR__ . '/extract1-2/';
@unlink($e . 'file2.txt');
@rmdir($e . 'one/level');
@rmdir($e . 'one');
@rmdir($e);
?>
--EXPECTF--
%sextract%cfile1.txt
%sextract%cfile2.txt
%sextract%cone
%sextract%csubdir
%sextract%csubdir%cectory
%sextract%csubdir%cectory%cfile.txt
string(2) "hi"
string(3) "hi3"
string(3) "hi2"
bool(false)
Phar::extractTo(): Argument #2 ($files) must be of type string|array|null, stdClass given
Phar::extractTo(): Argument #1 ($pathto) must be a valid path, array given
Invalid argument, extraction path must be non-zero length
Unable to use path "%soops" for extraction, it is a file, must be a directory
Invalid argument, array of filenames to extract contains non-string value
Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "file1.txt" to "%sextract/file1.txt", path already exists
string(5) "first"
string(2) "hi"
Cannot extract to "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa...", destination directory is too long for filesystem
Extraction from phar "%stempmanifest1.phar.php" failed: Cannot extract "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa..." to "%s...", extracted filename is too long for filesystem
|