From 55f50b485fdd4a8661e615702c4c6eebcaac370e Mon Sep 17 00:00:00 2001
From: Git'Fellow <12234510+solracsf@users.noreply.github.com>
Date: Fri, 7 Mar 2025 19:16:30 +0100
Subject: fix(files): Make sure file pointer exists

Signed-off-by: Git'Fellow <12234510+solracsf@users.noreply.github.com>
---
 lib/private/Files/Type/Detection.php | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php
index 3676a9b736c..48907b3473f 100644
--- a/lib/private/Files/Type/Detection.php
+++ b/lib/private/Files/Type/Detection.php
@@ -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';
 	}
 
-- 
cgit v1.2.3