xref: /PHP-8.3/ext/fileinfo/tests/bug61964.phpt (revision bd9f4fa6)
1--TEST--
2Bug #61964 (finfo_open with directory cause invalid free)
3--EXTENSIONS--
4fileinfo
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--EXPECTF--
47bool(false)%A
48object(finfo)#%d (0) {
49}
50object(finfo)#%d (0) {
51}
52bool(false)%A
53Warning: finfo_open(): offset `string' invalid in %sbug61964.php on line %d
54
55Warning: finfo_open(): offset ` Core' invalid in %sbug61964.php on line %d
56
57Warning: finfo_open(): offset ` Me' invalid in %sbug61964.php on line %d
58
59Warning: finfo_open(): offset `a' invalid in %sbug61964.php on line %d
60
61Warning: finfo_open(): offset `b' invalid in %sbug61964.php on line %d
62
63Warning: finfo_open(): Failed to load magic database at "%sbug61964" in %sbug61964.php on line %d
64DONE: testing dir with files
65