mirror of
https://github.com/php/php-src.git
synced 2026-04-17 21:11:02 +02:00
Currently we treat paths with null bytes as a TypeError, which is incorrect, and rather inconsistent, as we treat empty paths as ValueError. We do this because the error is generated by zpp and it's easier to always throw TypeError there. This changes the zpp implementation to throw a TypeError only if the type is actually wrong and throw ValueError for null bytes. The error message is also split accordingly, to be more precise. Closes GH-6094.
45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
--TEST--
|
|
Phar: test edge cases of fopen() function interception #2
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded("phar")) die("skip"); ?>
|
|
--INI--
|
|
phar.readonly=0
|
|
--FILE--
|
|
<?php
|
|
Phar::interceptFileFuncs();
|
|
$fname = __DIR__ . '/' . basename(__FILE__, '.php') . '.phar.php';
|
|
$pname = 'phar://' . $fname;
|
|
|
|
try {
|
|
fopen(array(), 'r');
|
|
} catch (TypeError $e) {
|
|
echo $e->getMessage(), "\n";
|
|
}
|
|
chdir(__DIR__);
|
|
file_put_contents($fname, "blah\n");
|
|
file_put_contents("fopen_edgecases2.txt", "test\n");
|
|
$a = fopen($fname, 'rb');
|
|
echo fread($a, 1000);
|
|
fclose($a);
|
|
unlink($fname);
|
|
mkdir($pname . '/oops');
|
|
file_put_contents($pname . '/foo/hi', '<?php
|
|
$context = stream_context_create();
|
|
$a = fopen("fopen_edgecases2.txt", "rb", false, $context);
|
|
echo fread($a, 1000);
|
|
fclose($a);
|
|
fopen("../oops", "r");
|
|
?>
|
|
');
|
|
include $pname . '/foo/hi';
|
|
?>
|
|
--CLEAN--
|
|
<?php unlink(__DIR__ . '/' . basename(__FILE__, '.clean.php') . '.phar.php'); ?>
|
|
<?php unlink(__DIR__ . '/fopen_edgecases2.txt'); ?>
|
|
--EXPECTF--
|
|
fopen(): Argument #1 ($filename) must be of type string, array given
|
|
blah
|
|
test
|
|
|
|
Warning: fopen(phar://%sfopen_edgecases2.phar.php/oops): Failed to open stream: phar error: path "oops" is a directory in phar://%sfopen_edgecases2.phar.php/foo/hi on line %d
|