[php-src] Issue #20679: finfo_file() doesn't work on remote resources

From: Date: Wed, 10 Dec 2025 16:45:21 +0000
Subject: [php-src] Issue #20679: finfo_file() doesn't work on remote resources
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-251374@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/20679 Author: ndossche ### Description The following code: ```php <?php $f = finfo_open(); var_dump(finfo_file($f,"https://example.com")); ``` Resulted in this output: ``` bool(false) ``` But I expected this output instead: ``` string(53) "HTML document, ASCII text, with very long lines (512)" ``` The reason this happens is because of the stat call in finfo_file(). This shouldn't be done on remote resources. E.g. smth like this would work. Ideally, we should differentiate between statable and non-statable streams though ```diff diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c index baae7571549..50695981796 100644 --- a/ext/fileinfo/fileinfo.c +++ b/ext/fileinfo/fileinfo.c @@ -268,11 +268,12 @@ static const char* php_fileinfo_from_path(struct magic_set *magic, const zend_st if (php_stream_stat(stream, &ssb) == SUCCESS) { if (ssb.sb.st_mode & S_IFDIR) { ret_val = "directory"; - } else { - ret_val = magic_stream(magic, stream); - if (UNEXPECTED(ret_val == NULL)) { - php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic)); - } + } + } + if (!ret_val) { + ret_val = magic_stream(magic, stream); + if (UNEXPECTED(ret_val == NULL)) { + php_error_docref(NULL, E_WARNING, "Failed identify data %d:%s", magic_errno(magic), magic_error(magic)); } } ``` ### PHP Version ```plain 8.3+ ``` ### Operating System _No response_

« previous php.bugs (#251374) next »