xref: /PHP-7.1/ext/fileinfo/tests/bug61964.phpt (revision 40195317)
1--TEST--
2Bug #61964 (finfo_open with directory cause invalid free)
3--SKIPIF--
4<?php require_once(dirname(__FILE__) . '/skipif.inc'); ?>
5--FILE--
6<?php
7
8$magic_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'magic';
9
10$ret = @finfo_open(FILEINFO_NONE, $magic_file . ".non-exits");
11var_dump($ret);
12
13$dir = __DIR__ . "/test-folder";
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)
49resource(%d) of type (file_info)
50resource(%d) of type (file_info)
51bool(false)
52
53Notice: finfo_open(): Warning: offset `string' invalid in %sbug61964.php on line %d
54
55Notice: finfo_open(): Warning: offset ` Core' invalid in %sbug61964.php on line %d
56
57Notice: finfo_open(): Warning: type `Core' invalid in %sbug61964.php on line %d
58
59Notice: finfo_open(): Warning: offset ` Me' invalid in %sbug61964.php on line %d
60
61Notice: finfo_open(): Warning: type `Me' invalid in %sbug61964.php on line %d
62
63Notice: finfo_open(): Warning: offset `a' invalid in %sbug61964.php on line %d
64
65Notice: finfo_open(): Warning: type `a' invalid in %sbug61964.php on line %d
66
67Notice: finfo_open(): Warning: offset `b' invalid in %sbug61964.php on line %d
68
69Notice: finfo_open(): Warning: type `b' invalid in %sbug61964.php on line %d
70
71Warning: finfo_open(): Failed to load magic database at '%stest-folder'. in %sbug61964.php on line %d
72DONE: testing dir with files
73===DONE===
74