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