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. --- activestorage/test/analyzer/image_analyzer_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activestorage/test/analyzer/image_analyzer_test.rb') diff --git a/activestorage/test/analyzer/image_analyzer_test.rb b/activestorage/test/analyzer/image_analyzer_test.rb index 55bb5e7280..73438c15ab 100644 --- a/activestorage/test/analyzer/image_analyzer_test.rb +++ b/activestorage/test/analyzer/image_analyzer_test.rb @@ -29,4 +29,12 @@ class ActiveStorage::Analyzer::ImageAnalyzerTest < ActiveSupport::TestCase assert_equal 792, metadata[:width] assert_equal 584, metadata[:height] end + + test "analyzing an unsupported image type" do + blob = create_blob(data: "bad", filename: "bad_file.bad", content_type: "image/bad_type") + metadata = extract_metadata_from(blob) + + assert_nil metadata[:width] + assert_nil metadata[:heigh] + end end -- cgit v1.2.3