Skip to content

Fixed GH-18267 finfo_file() crashing on invalid URL protocol. #18269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
14 changes: 14 additions & 0 deletions ext/fileinfo/tests/gh18267.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
--TEST--
GH-18267 finfo_file() assertion trigger on NULL stream context
--EXTENSIONS--
fileinfo
--FILE--
<?php
$cls = new finfo();
try {
$cls->file("test",FILEINFO_NONE, STDERR);
} catch (\TypeError $e) {
echo $e->getMessage();
}
--EXPECT--
finfo::file(): supplied resource is not a valid Stream-Context resource
Loading