Defect #44620 ยป 0001-Prevent-serving-partially-written-thumbnails.patch
| lib/redmine/thumbnail.rb | ||
|---|---|---|
|
directory = File.dirname(target)
|
||
|
FileUtils.mkdir_p directory
|
||
|
# Write to a temporary file first so that concurrent requests never
|
||
|
# serve a partially written thumbnail
|
||
|
output = File.join(directory, "#{Redmine::Utils.random_hex(8)}.#{File.basename(target)}")
|
||
|
size_option = "#{size}x#{size}>"
|
||
|
if mime_type == 'application/pdf'
|
||
|
return nil unless gs_available?
|
||
|
return nil unless valid_pdf_magic?(source)
|
||
|
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote "#{source}[0]"} -thumbnail #{shell_quote size_option} #{shell_quote "png:#{target}"}"
|
||
|
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote "#{source}[0]"} -thumbnail #{shell_quote size_option} #{shell_quote "png:#{output}"}"
|
||
|
else
|
||
|
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -auto-orient -thumbnail #{shell_quote size_option} #{shell_quote target}"
|
||
|
cmd = "#{shell_quote CONVERT_BIN} #{shell_quote source} -auto-orient -thumbnail #{shell_quote size_option} #{shell_quote output}"
|
||
|
end
|
||
|
pid = nil
|
||
| ... | ... | |
|
return nil
|
||
|
end
|
||
|
end
|
||
|
File.rename(output, target)
|
||
|
rescue Timeout::Error
|
||
|
if pid
|
||
|
begin
|
||
| ... | ... | |
|
end
|
||
|
logger.error("Creating thumbnail timed out:\nCommand: #{cmd}")
|
||
|
return nil
|
||
|
ensure
|
||
|
FileUtils.rm_f(output)
|
||
|
end
|
||
|
end
|
||
|
target
|
||