[php-src] PHP-8.6: Fix GH-24289: finfo::file() reports the wrong argument number
| From: | lazerg via ndossche | Date: | Tue, 13 Oct 2026 16:52:58 +0000 |
| Subject: | [php-src] PHP-8.6: Fix GH-24289: finfo::file() reports the wrong argument number | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-142228@lists.php.net to get a copy of this message | ||
Author: lazerg (lazerg)
Committer: ndossche (ndossche)
Date: 2026-10-13T18:48:19+02:00
Commit: https://github.com/php/php-src/commit/19a50604f9d23c17e2ec26b6caaada777d79fa4d
Raw diff: https://github.com/php/php-src/commit/19a50604f9d23c17e2ec26b6caaada777d79fa4d.diff
Fix GH-24289: finfo::file() reports the wrong argument number
Closes GH-24290.
Changed paths:
A ext/fileinfo/tests/gh24289.phpt
M NEWS
M ext/fileinfo/fileinfo.c
Diff:
diff --git a/NEWS b/NEWS
index 4b34324de64b..98d3853e0b74 100644
--- a/NEWS
+++ b/NEWS
@@ -30,6 +30,10 @@ PHP NEWS
. Fixed bug GH-24229 (fcgi_close() passes shutdown() a literal 1, which is
SHUT_RD in WASI). (Ryosuke Ishibashi)
+- Fileinfo:
+ . Fixed bug GH-24289 (finfo::file() reports the wrong argument number for
+ an invalid $filename). (Lazizbek Ergashev)
+
- MBString:
. Fixed bug GH-23958 (truncated encoding names resolving to full names). (Kamil Tekiela)
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index 52172dfbd692..e935fb1489fd 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -373,8 +373,8 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
php_stream_wrapper *wrap;
php_stream_statbuf ssb;
- // Implementation is used for both finfo_file() and mimetype_emu()
- int buffer_param_num = (mimetype_emu ? 1 : 2);
+ // Implementation is used for finfo_file(), finfo::file() and mimetype_emu()
+ int buffer_param_num = (mimetype_emu || hasThis() ? 1 : 2);
if (buffer == NULL || buffer_len == 0) {
zend_argument_must_not_be_empty_error(buffer_param_num);
goto clean;
diff --git a/ext/fileinfo/tests/gh24289.phpt b/ext/fileinfo/tests/gh24289.phpt
new file mode 100644
index 000000000000..f33eb0f23726
--- /dev/null
+++ b/ext/fileinfo/tests/gh24289.phpt
@@ -0,0 +1,23 @@
+--TEST--
+GH-24289 (finfo::file() reports the wrong argument number for an invalid $filename)
+--EXTENSIONS--
+fileinfo
+--FILE--
+<?php
+
+$finfo = new finfo();
+try {
+ var_dump($finfo->file(''));
+} catch (\ValueError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+try {
+ var_dump($finfo->file("\0"));
+} catch (\TypeError $e) {
+ echo $e->getMessage() . \PHP_EOL;
+}
+
+?>
+--EXPECT--
+finfo::file(): Argument #1 ($filename) must not be empty
+finfo::file(): Argument #1 ($filename) must not contain any null bytes