-
Notifications
You must be signed in to change notification settings - Fork 8k
Open
Description
Description
The following code:
<?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 --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
8.3+
Operating System
No response
socivdias