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
# Uses ImageMagick to determing the dimensions of a file, passed in as either a
# 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
file = file.path if file.respond_to? "path"
raise(Paperclip::NotIdentifiedByImageMagickError.new("Cannot find the geometry of a file with a blank name")) if file.blank?
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_path.blank?
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::CommandNotFoundError => e
raise Paperclip::CommandNotFoundError.new("Could not run the `identify` command. Please install ImageMagick.")
end
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
# 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