From eea7066c5485425d7b628acd83a8aff8c96a9925 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 7 Apr 2025 13:26:55 +0100 Subject: [PATCH] Fixed GH-18267 finfo_file() crashing on invalid URL protocol. close GH-18269 --- ext/fileinfo/fileinfo.c | 3 +++ ext/fileinfo/tests/gh18267.phpt | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 ext/fileinfo/tests/gh18267.phpt diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index d3680c5755f2..c0cc8877bf99 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -344,6 +344,9 @@ PHP_FUNCTION(finfo_file) RETURN_THROWS(); } php_stream_context *context = php_stream_context_from_zval(zcontext, false); + if (!context) { + RETURN_THROWS(); + } /* Set options for the current file/buffer. */ if (options) { diff --git a/ext/fileinfo/tests/gh18267.phpt b/ext/fileinfo/tests/gh18267.phpt new file mode 100644 index 000000000000..ba7647288d1d --- /dev/null +++ b/ext/fileinfo/tests/gh18267.phpt @@ -0,0 +1,14 @@ +--TEST-- +GH-18267 finfo_file() assertion trigger on NULL stream context +--EXTENSIONS-- +fileinfo +--FILE-- +file("test",FILEINFO_NONE, STDERR); +} catch (\TypeError $e) { + echo $e->getMessage(); +} +--EXPECT-- +finfo::file(): supplied resource is not a valid Stream-Context resource