Skip to content
Draft
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
23 changes: 3 additions & 20 deletions ext/fileinfo/fileinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,38 +242,21 @@ static const char* php_fileinfo_from_path(struct magic_set *magic, const zend_st
ZEND_ASSERT(!zend_str_has_nul_byte(path));
ZEND_ASSERT(context != NULL);

/* determine if the file is a local file or remote URL */
const char *dummy;
php_stream_statbuf ssb;

const php_stream_wrapper *wrap = php_stream_locate_url_wrapper(ZSTR_VAL(path), &dummy, 0);
if (UNEXPECTED(wrap == NULL)) {
return NULL;
}

#ifdef PHP_WIN32
if (php_stream_stat_path_ex(ZSTR_VAL(path), 0, &ssb, context) == SUCCESS) {
if (ssb.sb.st_mode & S_IFDIR) {
return "directory";
}
}
#endif

php_stream *stream = php_stream_open_wrapper_ex(ZSTR_VAL(path), "rb", REPORT_ERRORS, NULL, context);
if (!stream) {
return NULL;
}

const char *ret_val = NULL;
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));
}
}
const char *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_stream_close(stream);
Expand Down
26 changes: 26 additions & 0 deletions ext/fileinfo/tests/remote_resource.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
--TEST--
GH-20679 (finfo_file() doesn't work on remote resources)
--EXTENSIONS--
fileinfo
--INI--
allow_url_fopen=1
--SKIPIF--
<?php
if (@!include "./ext/standard/tests/http/server.inc") die('skip server.inc not available');
http_server_skipif();
?>
--FILE--
<?php
require "./ext/standard/tests/http/server.inc";

['pid' => $pid, 'uri' => $uri] = http_server([
"data://text/plain,HTTP/1.0 200 Ok\r\n\r\n<html>foo",
], $output);

$f = finfo_open();
var_dump(finfo_file($f, $uri));

http_server_kill($pid);
?>
--EXPECT--
string(51) "HTML document, ASCII text, with no line terminators"
Loading