From 0057f85ad7340e34369e7a3eb23339777b96492a Mon Sep 17 00:00:00 2001 From: bladewing Date: Tue, 14 Jul 2020 23:10:53 +0200 Subject: [PATCH 1/2] Avoid substr() error when strpos returns false "Exception: substr() expects parameter 3 to be int, bool given" can occur on Line 378 $mimePart = substr($icon, 0, strpos($icon, '-')); This happens, when '-' is not found and strpos returns false instead of an int. When this occurs, e.g., Activity hangs. Signed-off-by: lui87kw --- lib/private/Files/Type/Detection.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index 4e7f89778a4b7..0a9de12700bf8 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -380,12 +380,15 @@ public function mimeTypeIcon($mimetype): string { } // Try only the first part of the filetype - $mimePart = substr($icon, 0, strpos($icon, '-')); - try { - $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg'); - return $this->mimetypeIcons[$mimetype]; - } catch (\RuntimeException $e) { - // Image for the first part of the mimetype not found + + if(strpos($icon, '-')) { + $mimePart = substr($icon, 0, strpos($icon, '-')); + try { + $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg'); + return $this->mimetypeIcons[$mimetype]; + } catch (\RuntimeException $e) { + // Image for the first part of the mimetype not found + } } $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/file.svg'); From 3952be00eced8cdc069c9ca54cef3d7b428d8e6c Mon Sep 17 00:00:00 2001 From: lui87kw Date: Tue, 14 Jul 2020 23:36:23 +0200 Subject: [PATCH 2/2] Extra white space to follow other ifs Signed-off-by: lui87kw --- lib/private/Files/Type/Detection.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Files/Type/Detection.php b/lib/private/Files/Type/Detection.php index 0a9de12700bf8..9e85115f0a9fb 100644 --- a/lib/private/Files/Type/Detection.php +++ b/lib/private/Files/Type/Detection.php @@ -381,7 +381,7 @@ public function mimeTypeIcon($mimetype): string { // Try only the first part of the filetype - if(strpos($icon, '-')) { + if (strpos($icon, '-')) { $mimePart = substr($icon, 0, strpos($icon, '-')); try { $this->mimetypeIcons[$mimetype] = $this->urlGenerator->imagePath('core', 'filetypes/' . $mimePart . '.svg');