lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb in ddr-antivirus-2.1.1 vs lib/ddr/antivirus/adapters/clamd_scanner_adapter.rb in ddr-antivirus-2.2.0

- old
+ new

@@ -24,10 +24,11 @@ raise ScannerError.new(result) end end def clamdscan(path) + check_file_size(path) if max_file_size output = make_readable(path) do command "--fdpass", safe_path(path) end [ output, $?.exitstatus ] end @@ -35,19 +36,28 @@ def version @version ||= command("-V").strip end def config - @config ||= `#{CONFIG}` + # If client and server are on separate hosts + # attempt to read config may raise an exception. + @config ||= `#{CONFIG}` rescue nil end def max_file_size if m = MAX_FILE_SIZE_RE.match(config) - m[1] + m[1].to_i end end private + + def check_file_size(path) + if (file_size = File.size(path)) > max_file_size + raise MaxFileSizeExceeded, "Unable to scan file \"#{path}\" because size (#{file_size})" \ + " exceeds clamconf MaxFileSize (#{max_file_size})." + end + end def command(*args) cmd = args.dup.unshift(SCANNER).join(" ") `#{cmd}` end