1--TEST--
2Phar: create with illegal path
3--SKIPIF--
4<?php if (!extension_loaded("phar")) die("skip"); ?>
5--INI--
6phar.readonly=0
7phar.require_hash=1
8--FILE--
9<?php
10
11$fname = dirname(__FILE__) . '/' . basename(__FILE__, '.php') . '.phar.php';
12$pname = 'phar://' . $fname;
13
14@unlink($fname);
15
16file_put_contents($pname . '/a.php?', "query");
17file_put_contents($pname . '/b.php?bla', "query");
18
19var_dump(file_get_contents($pname . '/a.php'));
20var_dump(file_get_contents($pname . '/b.php'));
21
22function error_handler($errno, $errmsg)
23{
24	echo "Error: $errmsg";
25}
26
27set_error_handler('error_handler');
28
29$count = 0;
30$checks = array(
31    '/', '.', '../', 'a/..', 'a/', 'b//a.php',
32    "Font\xE5\x84\xB7\xE9\xBB\x91pro.ttf", //two valid multi-byte characters
33    "\xF0\x9F\x98\x8D.ttf", // valid 4 byte char - smiling face with heart-shaped eyes
34    "Font\xE9\xBBpro.ttf", //Invalid multi-byte character - missing last byte
35    "Font\xBB\x91pro.ttf",   //Invalid multi-byte character - missing first byte
36    "Font\xC0\xAFpro.ttf",   //Invalid multi-byte character - invalid first byte
37    "Font\xF0\x80\x90\x90pro.ttf",   //Invalid multi-byte character - surrogate pair code point
38    "\xFC\x81\x81\x81\x81pro.ttf", //RFC 3629 limited char points to 0000-10FFFF aka 5 byte utf-8 not valid
39);
40foreach($checks as $check)
41{
42	$count++;
43	echo "$count:";
44	file_put_contents($pname . '/' . $check, "error");
45	echo "\n";
46}
47
48$phar = new Phar($fname);
49$checks = array("a\0");
50foreach($checks as $check)
51{
52	try
53	{
54		$phar[$check] = 'error';
55	}
56	catch(Exception $e)
57	{
58		echo 'Exception: ' . $e->getMessage() . "\n";
59	}
60}
61
62?>
63===DONE===
64--CLEAN--
65<?php unlink(dirname(__FILE__) . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
66--EXPECTF--
67string(5) "query"
68string(5) "query"
691:Error: file_put_contents(phar://%s//): failed to open stream: phar error: file "" in phar "%s" cannot be empty
702:Error: file_put_contents(phar://%s/.): failed to open stream: phar error: file "" in phar "%s" cannot be empty
713:Error: file_put_contents(phar://%s/../): failed to open stream: phar error: file "" in phar "%s" cannot be empty
724:Error: file_put_contents(phar://%s/a/..): failed to open stream: phar error: file "" in phar "%s" cannot be empty
735:
746:
757:
768:
779:Error: file_put_contents(phar://%s): failed to open stream: phar error: invalid path "%s" contains illegal character
7810:Error: file_put_contents(phar://%s): failed to open stream: phar error: invalid path "%s" contains illegal character
7911:Error: file_put_contents(phar://%s): failed to open stream: phar error: invalid path "%s" contains illegal character
8012:Error: file_put_contents(phar://%s): failed to open stream: phar error: invalid path "%s" contains illegal character
8113:Error: file_put_contents(phar://%s): failed to open stream: phar error: invalid path "%s" contains illegal character
82Error: Phar::offsetSet() expects parameter 1 to be a valid path, string given===DONE===
83