xref: /PHP-7.4/ext/fileinfo/tests/bug61964.phpt (revision 1cbcf0f4)
1--TEST--
2Bug #61964 (finfo_open with directory cause invalid free)
3--SKIPIF--
4<?php require_once(__DIR__ . '/skipif.inc'); ?>
5--FILE--
6<?php
7
8$magic_file = __DIR__ . DIRECTORY_SEPARATOR . 'magic';
9
10$ret = @finfo_open(FILEINFO_NONE, $magic_file . ".non-exits");
11var_dump($ret);
12
13$dir = __DIR__ . "/bug61964";
14@mkdir($dir);
15
16$magic_file_copy = $dir . "/magic.copy";
17$magic_file_copy2 = $magic_file_copy . "2";
18copy($magic_file, $magic_file_copy);
19copy($magic_file, $magic_file_copy2);
20
21$ret = finfo_open(FILEINFO_NONE, $dir);
22var_dump($ret);
23
24$ret = @finfo_open(FILEINFO_NONE, $dir);
25var_dump($ret);
26
27$ret = @finfo_open(FILEINFO_NONE, $dir. "/non-exits-dir");
28var_dump($ret);
29
30// write some test files to test folder
31file_put_contents($dir . "/test1.txt", "string\n> Core\n> Me");
32file_put_contents($dir . "/test2.txt", "a\nb\n");
33@mkdir($dir . "/test-inner-folder");
34
35finfo_open(FILEINFO_NONE, $dir);
36echo "DONE: testing dir with files\n";
37
38rmdir($dir . "/test-inner-folder");
39unlink($dir . "/test1.txt");
40unlink($dir . "/test2.txt");
41
42unlink($magic_file_copy);
43unlink($magic_file_copy2);
44rmdir($dir);
45?>
46===DONE===
47--EXPECTF--
48bool(false)%A
49resource(%d) of type (file_info)
50resource(%d) of type (file_info)
51bool(false)%A
52Notice: finfo_open(): Warning: offset `string' invalid in %sbug61964.php on line %d
53
54Notice: finfo_open(): Warning: offset ` Core' invalid in %sbug61964.php on line %d
55
56Notice: finfo_open(): Warning: offset ` Me' invalid in %sbug61964.php on line %d
57
58Notice: finfo_open(): Warning: offset `a' invalid in %sbug61964.php on line %d
59
60Notice: finfo_open(): Warning: offset `b' invalid in %sbug61964.php on line %d
61
62Warning: finfo_open(): Failed to load magic database at '%sbug61964'. in %sbug61964.php on line %d
63DONE: testing dir with files
64===DONE===
65