Merge pull request #51535 from nextcloud/backport/51333/stable30

[stable30] fix(files): Make sure file pointer exists
This commit is contained in:
Git'Fellow 2025-03-18 07:29:41 +01:00 committed by GitHub
commit 4b73246047
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -228,18 +228,18 @@ class Detection implements IMimeTypeDetector {
// lets see if it does have mime support
$path = escapeshellarg($path);
$fp = popen("test -f $path && file -b --mime-type $path", 'r');
$mimeType = fgets($fp);
pclose($fp);
if ($mimeType !== false) {
//trim the newline
$mimeType = trim($mimeType);
$mimeType = $this->getSecureMimeType($mimeType);
if ($mimeType !== 'application/octet-stream') {
if ($fp !== false) {
$mimeType = fgets($fp);
pclose($fp);
if ($mimeType !== false) {
//trim the newline
$mimeType = trim($mimeType);
$mimeType = $this->getSecureMimeType($mimeType);
return $mimeType;
}
}
}
return 'application/octet-stream';
}