xref: /PHP-8.4/ext/spl/tests/bug78863.phpt (revision 68195bd4)
1--TEST--
2Bug #78863 (DirectoryIterator class silently truncates after a null byte)
3--FILE--
4<?php
5$dir = __DIR__ . '/bug78863';
6mkdir($dir);
7touch("$dir/bad");
8mkdir("$dir/sub");
9touch("$dir/sub/good");
10
11$it = new DirectoryIterator(__DIR__ . "/bug78863\0/sub");
12foreach ($it as $fileinfo) {
13    if (!$fileinfo->isDot()) {
14        var_dump($fileinfo->getFilename());
15    }
16}
17?>
18--EXPECTF--
19Fatal error: Uncaught ValueError: DirectoryIterator::__construct(): Argument #1 ($directory) must not contain any null bytes in %s:%d
20Stack trace:
21#0 %s(%d): DirectoryIterator->__construct('%s')
22#1 {main}
23  thrown in %s on line %d
24--CLEAN--
25<?php
26$dir = __DIR__ . '/bug78863';
27unlink("$dir/sub/good");
28rmdir("$dir/sub");
29unlink("$dir/bad");
30rmdir($dir);
31?>
32