From 4d17d9533552ea620b83109c550e250a5c236291 Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Thu, 25 Feb 2016 22:31:45 +0100 Subject: [PATCH] Try to get mime data before hashing (cpu intensive) --- plugins/Oembed/OembedPlugin.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/plugins/Oembed/OembedPlugin.php b/plugins/Oembed/OembedPlugin.php index 44e4ac9318..196b07d75d 100644 --- a/plugins/Oembed/OembedPlugin.php +++ b/plugins/Oembed/OembedPlugin.php @@ -325,8 +325,10 @@ class OembedPlugin extends Plugin throw new UnsupportedMediaException(_('Image file had impossible geometry (0 width or height)')); } + $ext = File::guessMimeExtension($info['mime']); + // We'll trust sha256 (File::FILEHASH_ALG) not to have collision issues any time soon :) - $filename = hash(File::FILEHASH_ALG, $imgData) . '.' . common_supported_mime_to_ext($info['mime']); + $filename = hash(File::FILEHASH_ALG, $imgData) . ".{$ext}"; $fullpath = File_thumbnail::path($filename); // Write the file to disk. Throw Exception on failure if (!file_exists($fullpath) && file_put_contents($fullpath, $imgData) === false) {