From cb8c78628498d60844257c7d68ca6502f1e64af0 Mon Sep 17 00:00:00 2001 From: Joshua Ramon Enslin Date: Sun, 8 Nov 2020 13:06:05 +0100 Subject: [PATCH] Add check to ensure finfo_open works in ensure_file function --- MD_STD.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/MD_STD.php b/MD_STD.php index 73ef091..2438ed8 100644 --- a/MD_STD.php +++ b/MD_STD.php @@ -397,13 +397,15 @@ final class MD_STD { return; } - $finfo = \finfo_open(FILEINFO_MIME_TYPE); + if (!($finfo = \finfo_open(FILEINFO_MIME_TYPE))) { + throw new Exception("Cannot open finfo context"); + } if (!($mime_type = finfo_file($finfo, $filepath))) { throw new MDWrongFileType("Cannot get mime type of file: " . basename($filepath)); } \finfo_close($finfo); - if (!\in_array($mime_type, $accepted_mimetype)) { + if (!\in_array($mime_type, $accepted_mimetype, true)) { throw new MDWrongFileType("Incorrect mime type of file " . \basename($filepath) . ". Mime type is " . \mime_content_type($filepath) . ", accepted any of ['" . \implode("', '", $accepted_mimetype) . "']"); }