xref: /PHP-8.1/ext/phar/tests/bug64931/bug64931.phpt (revision 39131219)
1--TEST--
2Bug #64931 (phar_add_file is too restrictive on filename)
3--EXTENSIONS--
4phar
5--INI--
6phar.readonly=0
7--FILE--
8<?php
9
10echo "Test\n";
11
12@unlink(__DIR__."/bug64931.phar");
13$phar = new Phar(__DIR__."/bug64931.phar");
14$phar->addFile(__DIR__."/src/.pharignore", ".pharignore");
15try {
16    $phar->addFile(__DIR__."/src/.pharignore", ".phar/gotcha");
17} catch (Exception $e) {
18    echo "CAUGHT: ". $e->getMessage() ."\n";
19}
20
21try {
22    $phar->addFromString(".phar", "gotcha");
23} catch (Exception $e) {
24    echo "CAUGHT: ". $e->getMessage() ."\n";
25}
26
27try {
28    $phar->addFromString(".phar//", "gotcha");
29} catch (Exception $e) {
30    echo "CAUGHT: ". $e->getMessage() ."\n";
31}
32
33try {
34    $phar->addFromString(".phar\\", "gotcha");
35} catch (Exception $e) {
36    echo "CAUGHT: ". $e->getMessage() ."\n";
37}
38
39try {
40    $phar->addFromString(".phar\0", "gotcha");
41} catch (ValueError $e) {
42    echo "CAUGHT: ". $e->getMessage() ."\n";
43}
44
45?>
46--CLEAN--
47<?php
48@unlink(__DIR__."/bug64931.phar");
49?>
50--EXPECT--
51Test
52CAUGHT: Cannot create any files in magic ".phar" directory
53CAUGHT: Cannot create any files in magic ".phar" directory
54CAUGHT: Cannot create any files in magic ".phar" directory
55CAUGHT: Cannot create any files in magic ".phar" directory
56CAUGHT: Phar::addFromString(): Argument #1 ($localName) must not contain any null bytes
57