Commit a0681085 by Aldo Sarmiento Committed by Jon Yurek

Do not release reference to possible tempfile object

parent 0df5a960
...@@ -13,18 +13,20 @@ module Paperclip ...@@ -13,18 +13,20 @@ module Paperclip
# Uses ImageMagick to determing the dimensions of a file, passed in as either a # Uses ImageMagick to determing the dimensions of a file, passed in as either a
# File or path. # File or path.
# NOTE: (race cond) Do not reassign the 'file' variable inside this method as it is likely to be
# a Tempfile object, which would be eligible for file deletion when no longer referenced.
def self.from_file file def self.from_file file
file = file.path if file.respond_to? "path" file_path = file.respond_to?(:path) ? file.path : file
raise(Paperclip::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file.blank? raise(Paperclip::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file_path.blank?
geometry = begin geometry = begin
Paperclip.run("identify", "-format %wx%h :file", :file => "#{file}[0]") Paperclip.run("identify", "-format %wx%h :file", :file => "#{file_path}[0]")
rescue Cocaine::ExitStatusError rescue Cocaine::ExitStatusError
"" ""
rescue Cocaine::CommandNotFoundError => e rescue Cocaine::CommandNotFoundError => e
raise Paperclip::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.") raise Paperclip::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end end
parse(geometry) || parse(geometry) ||
raise(NotIdentifiedByImageMagickError.new("#{file} is not recognized by the 'identify' command.")) raise(NotIdentifiedByImageMagickError.new("#{file_path} is not recognized by the 'identify' command."))
end end
# Parses a "WxH" formatted string, where W is the width and H is the height. # Parses a "WxH" formatted string, where W is the width and H is the height.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment