Skip to content
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

Fix : check if is_file in getMimeType #590

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
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
50 changes: 26 additions & 24 deletions classes/ReassuranceActivity.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,32 +173,34 @@ public static function getAllBlockByStatus($id_lang = 1)
public static function getMimeType(string $filename)
{
$mimeType = false;
// Try with GD
if (function_exists('getimagesize')) {
$imageInfo = @getimagesize($filename);
if ($imageInfo) {
$mimeType = $imageInfo['mime'];
if (is_file($filename)) {
// Try with GD
if (function_exists('getimagesize')) {
$imageInfo = @getimagesize($filename);
if ($imageInfo) {
$mimeType = $imageInfo['mime'];
}
}
}
// Try with FileInfo
if (!$mimeType && function_exists('finfo_open')) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
$finfo = finfo_open($const);
$mimeType = finfo_file($finfo, $filename);
finfo_close($finfo);
}
// Try with Mime
if (!$mimeType && function_exists('mime_content_type')) {
$mimeType = mime_content_type($filename);
}
// Try with exec command and file binary
if (!$mimeType && function_exists('exec')) {
$mimeType = trim(exec('file -b --mime-type ' . escapeshellarg($filename)));
if (!$mimeType) {
$mimeType = trim(exec('file --mime ' . escapeshellarg($filename)));
// Try with FileInfo
if (!$mimeType && function_exists('finfo_open')) {
$const = defined('FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
$finfo = finfo_open($const);
$mimeType = finfo_file($finfo, $filename);
finfo_close($finfo);
}
// Try with Mime
if (!$mimeType && function_exists('mime_content_type')) {
$mimeType = mime_content_type($filename);
}
if (!$mimeType) {
$mimeType = trim(exec('file -bi ' . escapeshellarg($filename)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waaaaah 🤯 I did not know this code performed an exec... it's a bit frightening 😅 for security issues

// Try with exec command and file binary
if (!$mimeType && function_exists('exec')) {
$mimeType = trim(exec('file -b --mime-type ' . escapeshellarg($filename)));
if (!$mimeType) {
$mimeType = trim(exec('file --mime ' . escapeshellarg($filename)));
}
if (!$mimeType) {
$mimeType = trim(exec('file -bi ' . escapeshellarg($filename)));
}
}
}

Expand Down