aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage
diff options
context:
space:
mode:
authorGeorge Claghorn <george@basecamp.com>2019-04-24 08:25:55 -0400
committerGitHub <noreply@github.com>2019-04-24 08:25:55 -0400
commitc7b03de1dd64b6d3ed0c098fea95b0e61cc83d0b (patch)
tree79f556b73d55ce61d13ade0afac48f4700269188 /activestorage
parent5575bd7b22e8e11ba8e2fdac4a92aab931d4f9f9 (diff)
parent6133dad86970951094bdb4a603bc80c4968a9667 (diff)
downloadrails-c7b03de1dd64b6d3ed0c098fea95b0e61cc83d0b.tar.gz
rails-c7b03de1dd64b6d3ed0c098fea95b0e61cc83d0b.tar.bz2
rails-c7b03de1dd64b6d3ed0c098fea95b0e61cc83d0b.zip
Merge pull request #36072 from itsWill/dont_fail_on_unsuported_images
Don't fail ImageAnalyzer on unsupported types
Diffstat (limited to 'activestorage')
-rw-r--r--activestorage/CHANGELOG.md5
-rw-r--r--activestorage/lib/active_storage/analyzer/image_analyzer.rb15
-rw-r--r--activestorage/test/analyzer/image_analyzer_test.rb8
3 files changed, 24 insertions, 4 deletions
diff --git a/activestorage/CHANGELOG.md b/activestorage/CHANGELOG.md
index d524ecf7d6..ff5dd884e3 100644
--- a/activestorage/CHANGELOG.md
+++ b/activestorage/CHANGELOG.md
@@ -1,3 +1,8 @@
+* Don't raise when analyzing an unsupported image type by ImageMagick
+ Fixes: #36065
+
+ *Guilherme Mansur*
+
* Permit generating variants of BMP images.
*Younes Serraj*
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)
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