create_path_error.phpt 2.9 KB

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