Skip to content

Commit

Permalink
Make sure we only invoke Imagemagick if this is actually an image (#2…
Browse files Browse the repository at this point in the history
…2721).

git-svn-id: http://svn.redmine.org/redmine/trunk@15362 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
jplang committed May 4, 2016
1 parent fcb4e51 commit bf81c96
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
Expand Up @@ -14,6 +14,7 @@ gem "protected_attributes"
gem "actionpack-action_caching"
gem "actionpack-xml_parser"
gem "roadie-rails"
gem "mimemagic"

# Request at least nokogiri 1.6.7.2 because of security advisories
gem "nokogiri", ">= 1.6.7.2"
Expand Down
5 changes: 5 additions & 0 deletions lib/redmine/thumbnail.rb
Expand Up @@ -16,6 +16,7 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

require 'fileutils'
require 'mimemagic'

module Redmine
module Thumbnail
Expand All @@ -27,6 +28,10 @@ module Thumbnail
def self.generate(source, target, size)
return nil unless convert_available?
unless File.exists?(target)
# Make sure we only invoke Imagemagick if this is actually an image
unless File.open(source) {|f| MimeMagic.by_magic(f).try(:image?)}
return nil
end
directory = File.dirname(target)
unless File.exists?(directory)
FileUtils.mkdir_p directory
Expand Down

0 comments on commit bf81c96

Please sign in to comment.