ratonvirus 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4b47a31e5d403f39f0b7496a292532b2dbaa5c38fe624368b09a2cb28c949623
4
- data.tar.gz: 7a37d2f6d7b20e45c417b87ea22bbadbaf434714c1ce7082c1b4a4d87b646845
3
+ metadata.gz: f4ccf906781401ec2e9126acf96165d278b0dce5ecf2b10cfa71373490433d98
4
+ data.tar.gz: dc56500ae5839a3987c47e96d05ceb9e4627c412edd953d0dbf1fc2c02069c52
5
5
  SHA512:
6
- metadata.gz: a52088960f46b6e4aad10616e9f2b65ad082490bd7158484178f88cc6aa68fa76397e471fa4e791e38cd51bcca799aabdbe868656c03226a9157bb2d82be4aaa
7
- data.tar.gz: 62b103a30f7711cad63d9c9095eec42f98baf372b7fe2308ee03dc3ae063a74bf458afa8026e36ac10aa184df40302a9d721eafbbd93f6fc92efcc090efd9c4c
6
+ metadata.gz: 830a364f9355592158d7580c8755b576ea6a591951e48832ec6d83a308d5d5b0bdcaec3822d7dd47a5120eebc264c2037762202e0f53c42c3d10781d8c67f081
7
+ data.tar.gz: 68562672a90dafe0d4705378cc94549d2cf64858987a14901b73607da595b747e72f0d45c52a06f9b1595aba6ab3118998ee5e23901ff438f31bdf6aa399852f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # v0.1.2
2
+
3
+ Fixed:
4
+
5
+ - Backport: Issue related with scanning files with CarrierWave storage engine using remote storage engines such as Fog.
6
+ Related to #9
7
+
8
+
9
+ # v0.1.1
10
+
11
+ Fixed:
12
+
13
+ - Rescue file not found exception for blob.download [#2](https://github.com/mainio/ratonvirus/pull/2)
14
+
1
15
  # v0.1.0
2
16
 
3
17
  Initial public release.
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  Rails antivirus made easy.
4
4
  Developed by [Mainio Tech](https://www.mainiotech.fi/).
5
5
 
6
- [![Build Status](https://travis-ci.org/mainio/ratonvirus.svg?branch=master)](https://travis-ci.org/mainio/ratonvirus)
6
+ [![Build Status](https://travis-ci.com/mainio/ratonvirus.svg?branch=master)](https://travis-ci.com/mainio/ratonvirus)
7
7
  [![codecov](https://codecov.io/gh/mainio/ratonvirus/branch/master/graph/badge.svg)](https://codecov.io/gh/mainio/ratonvirus)
8
8
 
9
9
  Ratonvirus allows your Rails application to rat on the viruses that your users
data/lib/ratonvirus.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "ratonvirus/scanner/support/callbacks"
12
12
  require_relative "ratonvirus/scanner/base"
13
13
  require_relative "ratonvirus/scanner/eicar"
14
14
  require_relative "ratonvirus/scanner/addon/remove_infected"
15
+ require_relative "ratonvirus/storage/support/io_handling"
15
16
  require_relative "ratonvirus/storage/base"
16
17
  require_relative "ratonvirus/storage/filepath"
17
18
  require_relative "ratonvirus/storage/active_storage"
@@ -3,6 +3,8 @@
3
3
  module Ratonvirus
4
4
  module Storage
5
5
  class Carrierwave < Base
6
+ include Ratonvirus::Storage::Support::IoHandling
7
+
6
8
  def changed?(record, attribute)
7
9
  record.public_send :"#{attribute}_changed?"
8
10
  end
@@ -15,12 +17,22 @@ module Ratonvirus
15
17
  end
16
18
  end
17
19
 
18
- def asset_path(asset)
20
+ def asset_path(asset, &block)
19
21
  return unless block_given?
20
22
  return if asset.nil?
21
23
  return if asset.file.nil?
22
24
 
23
- yield asset.file.path
25
+ # If the file is a local SanitizedFile, it is faster to run the scan
26
+ # directly against that file instead of copying it to a tempfile first
27
+ # as below for external file storages.
28
+ return yield asset.file.path if asset.file.is_a?(::CarrierWave::SanitizedFile)
29
+
30
+ # The file could be externally stored, so we need to read it to memory
31
+ # in order to create a temporary file for the scanner to perform the
32
+ # scan on.
33
+ io = StringIO.new(asset.file.read)
34
+ ext = File.extname(asset.file.path)
35
+ io_path(io, ext, &block)
24
36
  end
25
37
 
26
38
  def asset_remove(asset)
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tempfile"
4
+
5
+ module Ratonvirus
6
+ module Storage
7
+ module Support
8
+ module IoHandling
9
+ private
10
+
11
+ # This creates a local copy of the io contents for the scanning process.
12
+ # A local copy is needed for processing because the io object may be a
13
+ # file stream in the memory which may not have a path associated with it
14
+ # on the filesystem.
15
+ def io_path(io, extension)
16
+ tempfile = Tempfile.open(
17
+ ["Ratonvirus", extension],
18
+ tempdir
19
+ )
20
+ # Important for the scanner to be able to access the file.
21
+ prepare_for_scanner tempfile.path
22
+
23
+ begin
24
+ tempfile.binmode
25
+ IO.copy_stream(io, tempfile)
26
+ tempfile.flush
27
+ tempfile.rewind
28
+
29
+ yield tempfile.path
30
+ ensure
31
+ tempfile.close!
32
+ end
33
+ end
34
+
35
+ def tempdir
36
+ Dir.tmpdir
37
+ end
38
+
39
+ def prepare_for_scanner(filepath)
40
+ # Important for the scanner to be able to access the file.
41
+ File.chmod(0o644, filepath)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ratonvirus
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ratonvirus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Antti Hukkanen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-27 00:00:00.000000000 Z
11
+ date: 2021-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -177,6 +177,7 @@ files:
177
177
  - lib/ratonvirus/storage/carrierwave.rb
178
178
  - lib/ratonvirus/storage/filepath.rb
179
179
  - lib/ratonvirus/storage/multi.rb
180
+ - lib/ratonvirus/storage/support/io_handling.rb
180
181
  - lib/ratonvirus/support/backend.rb
181
182
  - lib/ratonvirus/version.rb
182
183
  - lib/tasks/ratonvirus.rake