From 6133dad86970951094bdb4a603bc80c4968a9667 Mon Sep 17 00:00:00 2001 From: Guilherme Mansur Date: Tue, 23 Apr 2019 16:11:10 -0400 Subject: Don't fail ImageAnalyzer on unsupported types Fix: #36065 The IamgeAnalyzer passes a image to ImageMagick without checking if the image is supported by ImageMagick. This patch checks that image is supported and if not logs an error and returns an empty hash instead of raising an error. This is the same error handling we do when we encounter a LoadError when mini_magick is not installed. --- .../lib/active_storage/analyzer/image_analyzer.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'activestorage/lib/active_storage/analyzer/image_analyzer.rb') diff --git a/activestorage/lib/active_storage/analyzer/image_analyzer.rb b/activestorage/lib/active_storage/analyzer/image_analyzer.rb index 3b39de91be..c8bc8fe953 100644 --- a/activestorage/lib/active_storage/analyzer/image_analyzer.rb +++ b/activestorage/lib/active_storage/analyzer/image_analyzer.rb @@ -25,17 +25,24 @@ module ActiveStorage { width: image.width, height: image.height } end end - rescue LoadError - logger.info "Skipping image analysis because the mini_magick gem isn't installed" - {} end private def read_image download_blob_to_tempfile do |file| require "mini_magick" - yield MiniMagick::Image.new(file.path) + image = MiniMagick::Image.new(file.path) + + if image.valid? + yield image + else + logger.info "Skipping image analysis because ImageMagick doesn't support the file" + {} + end end + rescue LoadError + logger.info "Skipping image analysis because the mini_magick gem isn't installed" + {} end def rotated_image?(image) -- cgit v1.2.3