[php-src] master: QA - finfo_open - increase test coverage (#13839)
| From: | Juan Morales via GitHub | Date: | Sat, 30 Mar 2024 14:16:11 +0000 |
| Subject: | [php-src] master: QA - finfo_open - increase test coverage (#13839) | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-127895@lists.php.net to get a copy of this message | ||
Author: Juan Morales (juan-morales)
Committer: GitHub (web-flow)
Pusher: nielsdos
Date: 2024-03-30T15:16:06+01:00
Commit: https://github.com/php/php-src/commit/186465b1ddcf203ddffb5d24bae897508c711586
Raw diff: https://github.com/php/php-src/commit/186465b1ddcf203ddffb5d24bae897508c711586.diff
QA - finfo_open - increase test coverage (#13839)
Changed paths:
A ext/fileinfo/tests/finfo_open_003.phpt
A ext/fileinfo/tests/finfo_open_004.phpt
M ext/fileinfo/tests/finfo_open_001.phpt
Diff:
diff --git a/ext/fileinfo/tests/finfo_open_001.phpt b/ext/fileinfo/tests/finfo_open_001.phpt
index 376b3ac1760ff..21b90042f0fd8 100644
--- a/ext/fileinfo/tests/finfo_open_001.phpt
+++ b/ext/fileinfo/tests/finfo_open_001.phpt
@@ -4,7 +4,6 @@ finfo_open(): Testing magic_file names
fileinfo
--FILE--
<?php
-
try {
var_dump(finfo_open(FILEINFO_MIME, "\0"));
} catch (ValueError $e) {
@@ -17,6 +16,26 @@ var_dump(finfo_open(FILEINFO_MIME, 123));
var_dump(finfo_open(FILEINFO_MIME, 1.0));
var_dump(finfo_open(FILEINFO_MIME, '/foo/bar/inexistent'));
+var_dump($obj = new finfo(FILEINFO_MIME, NULL));
+var_dump($obj = new finfo(FILEINFO_MIME, ''));
+
+try {
+ var_dump($obj = new finfo(FILEINFO_MIME, 123));
+} catch (\Exception $e) {
+ echo $e->getMessage() . PHP_EOL;
+}
+
+try {
+ var_dump($obj = new finfo(FILEINFO_MIME, 1.0));
+} catch (\Exception $e) {
+ echo $e->getMessage() . PHP_EOL;
+}
+
+try {
+ var_dump($obj = new finfo(FILEINFO_MIME, '/foo/bar/inexistent'));
+} catch (\Exception $e) {
+ echo $e->getMessage() . PHP_EOL;
+}
?>
--EXPECTF--
finfo_open(): Argument #2 ($magic_database) must not contain any null bytes
@@ -45,3 +64,10 @@ Warning: finfo_open(%sinexistent): Failed to open stream: No such file or direct
Warning: finfo_open(): Failed to load magic database at "%sinexistent" in %s on line %d
bool(false)
+object(finfo)#%d (%d) {
+}
+object(finfo)#%d (%d) {
+}
+finfo::__construct(%s123): Failed to open stream: No such file or directory
+finfo::__construct(%s1): Failed to open stream: No such file or directory
+finfo::__construct(%sinexistent): Failed to open stream: No such file or directory
diff --git a/ext/fileinfo/tests/finfo_open_003.phpt b/ext/fileinfo/tests/finfo_open_003.phpt
new file mode 100644
index 0000000000000..39a45a61c6ffb
--- /dev/null
+++ b/ext/fileinfo/tests/finfo_open_003.phpt
@@ -0,0 +1,19 @@
+--TEST--
+finfo_open(): Testing magic_file names
+--EXTENSIONS--
+fileinfo
+--FILE--
+<?php
+$buggyPath = str_repeat('a', PHP_MAXPATHLEN + 1);
+
+var_dump(finfo_open(FILEINFO_MIME, $buggyPath));
+
+try {
+ $object = new finfo(FILEINFO_MIME, $buggyPath);
+} catch (\Exception $ex) {
+ echo "TEST:" . $ex->getMessage() . PHP_EOL;
+}
+?>
+--EXPECTF--
+bool(false)
+TEST:Constructor failed
diff --git a/ext/fileinfo/tests/finfo_open_004.phpt b/ext/fileinfo/tests/finfo_open_004.phpt
new file mode 100644
index 0000000000000..ff911bc750865
--- /dev/null
+++ b/ext/fileinfo/tests/finfo_open_004.phpt
@@ -0,0 +1,22 @@
+--TEST--
+finfo_open(): Testing magic_file names
+--EXTENSIONS--
+fileinfo
+--INI--
+open_basedir='.'
+--FILE--
+<?php
+$buggyPath = str_repeat('a', PHP_MAXPATHLEN + 1);
+
+var_dump(finfo_open(FILEINFO_MIME, $buggyPath));
+
+try {
+ $object = new finfo(FILEINFO_MIME, $buggyPath);
+} catch (\Exception $ex) {
+ echo "TEST:" . $ex->getMessage() . PHP_EOL;
+}
+?>
+--EXPECTF--
+Warning: finfo_open(): File name is longer than the maximum allowed path length on this platform
(%d): %s in %s on line %d
+bool(false)
+TEST:finfo::__construct(): File name is longer than the maximum allowed path length on this
platform (%d): %s