From 2eba34be0f90e98e81310765cee184dc3285ed33 Mon Sep 17 00:00:00 2001 From: lazerg Date: Tue, 13 Oct 2026 14:47:20 +0500 Subject: [PATCH 1/2] Fix GH-24289: finfo::file() reports the wrong argument number --- NEWS | 4 ++++ ext/fileinfo/fileinfo.c | 4 ++-- ext/fileinfo/tests/gh24289.phpt | 23 +++++++++++++++++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 ext/fileinfo/tests/gh24289.phpt 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..008121ebd3e8 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 || getThis() ? 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-- +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 From 5ffdb80dfb4ba572e9fb27711a7cc1582e6e0a27 Mon Sep 17 00:00:00 2001 From: lazerg Date: Tue, 13 Oct 2026 15:17:25 +0500 Subject: [PATCH 2/2] Use hasThis() instead of getThis() --- ext/fileinfo/fileinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index 008121ebd3e8..e935fb1489fd 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -374,7 +374,7 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime php_stream_statbuf ssb; // Implementation is used for finfo_file(), finfo::file() and mimetype_emu() - int buffer_param_num = (mimetype_emu || getThis() ? 1 : 2); + 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;