Skip to content

Commit 2d39c78

Browse files
authored
Fixed GH-18267 finfo_file() crashing on invalid URL protocol. (#18269)
Close GH-18267
1 parent aa0c54d commit 2d39c78

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

ext/fileinfo/fileinfo.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ PHP_FUNCTION(finfo_file)
344344
RETURN_THROWS();
345345
}
346346
php_stream_context *context = php_stream_context_from_zval(zcontext, false);
347+
if (!context) {
348+
RETURN_THROWS();
349+
}
347350

348351
/* Set options for the current file/buffer. */
349352
if (options) {

ext/fileinfo/tests/gh18267.phpt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
--TEST--
2+
GH-18267 finfo_file() assertion trigger on NULL stream context
3+
--EXTENSIONS--
4+
fileinfo
5+
--FILE--
6+
<?php
7+
$cls = new finfo();
8+
try {
9+
$cls->file("test",FILEINFO_NONE, STDERR);
10+
} catch (\TypeError $e) {
11+
echo $e->getMessage();
12+
}
13+
--EXPECT--
14+
finfo::file(): supplied resource is not a valid Stream-Context resource

0 commit comments

Comments
 (0)