create_path_error.phpt 2.8 KB

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