Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

Commit

Permalink
Increase attachment file size from int (4 bytes) to bigint (8 bytes).
Browse files Browse the repository at this point in the history
The 4 byte limit is starting to wrap around; some complaints are being seen
online, e.g.
https://stackoverflow.com/questions/34477248/rails-paperclip-rangeerror/47999887#47999887 .

Use `#sql_type` instead of `#type` in the tests. The `#type` is the category --
string, integer, datetime -- but the `#sql_type` is the storage specifics --
`TEXT`, `VARCHAR`, `BIGINT`, `DATE. Switch to the `#sql_type` so we can be sure
it's being stored correctly.
  • Loading branch information
alenzamanyan authored and Mike Burns committed Jul 27, 2018
1 parent 90f9121 commit 34ec355
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 52 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ master:
* Improvement: Better handling of the content-disposition header. Now supports file name that is either
enclosed or not in double quotes and is case insensitive as per RC6266 grammar
* Improvement: Files without an extension will now be checked for spoofing attempts
* Change database column type of attachment file size from unsigned 4-byte
`integer` to unsigned 8-byte `bigint`. The former type limits attachment
size to just over 2GB, which can easily be exceeded by a large video file.

6.0.0 (2018-03-09):

Expand Down
4 changes: 2 additions & 2 deletions features/step_definitions/attachment_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def attachment_path(filename)
expect_columns = [
["#{attachment_name}_file_name", :string],
["#{attachment_name}_content_type", :string],
["#{attachment_name}_file_size", :integer],
["#{attachment_name}_file_size", :bigint],
["#{attachment_name}_updated_at", :datetime]
]
expect(columns).to include(*expect_columns)
Expand All @@ -101,7 +101,7 @@ def attachment_path(filename)
expect_columns = [
["#{attachment_name}_file_name", :string],
["#{attachment_name}_content_type", :string],
["#{attachment_name}_file_size", :integer],
["#{attachment_name}_file_size", :bigint],
["#{attachment_name}_updated_at", :datetime]
]

Expand Down
2 changes: 1 addition & 1 deletion lib/paperclip/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Paperclip
module Schema
COLUMNS = {:file_name => :string,
:content_type => :string,
:file_size => :integer,
:file_size => :bigint,
:updated_at => :datetime}

def self.included(base)
Expand Down
2 changes: 1 addition & 1 deletion spec/paperclip/attachment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1416,7 +1416,7 @@ def call(filename)

context "and avatar_file_size column" do
before do
ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :integer
ActiveRecord::Base.connection.add_column :dummies, :avatar_file_size, :bigint
rebuild_class
@dummy = Dummy.new
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
before do
reset_table("dummies") do |d|
d.string :avatar_file_name
d.integer :avatar_file_size
d.bigint :avatar_file_size
end
reset_class "Dummy"
Dummy.do_not_validate_attachment_file_type :avatar
Expand Down
92 changes: 46 additions & 46 deletions spec/paperclip/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@
end
end

columns = Dummy.columns.map{ |column| [column.name, column.type] }
columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }

expect(columns).to include(['avatar_file_name', :string])
expect(columns).to include(['avatar_content_type', :string])
expect(columns).to include(['avatar_file_size', :integer])
expect(columns).to include(['avatar_updated_at', :datetime])
expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', "datetime"])
end

it "displays deprecation warning" do
Expand All @@ -50,12 +50,12 @@
end

it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] }
columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }

expect(columns).to include(['avatar_file_name', :string])
expect(columns).to include(['avatar_content_type', :string])
expect(columns).to include(['avatar_file_size', :integer])
expect(columns).to include(['avatar_updated_at', :datetime])
expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', "datetime"])
end
end

Expand Down Expand Up @@ -89,12 +89,12 @@
end

it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] }
columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }

expect(columns).to include(['avatar_file_name', :string])
expect(columns).to include(['avatar_content_type', :string])
expect(columns).to include(['avatar_file_size', :integer])
expect(columns).to include(['avatar_updated_at', :datetime])
expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', "datetime"])
end
end

Expand All @@ -119,16 +119,16 @@
end

it "creates attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] }
columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }

expect(columns).to include(['avatar_file_name', :string])
expect(columns).to include(['avatar_content_type', :string])
expect(columns).to include(['avatar_file_size', :integer])
expect(columns).to include(['avatar_updated_at', :datetime])
expect(columns).to include(['photo_file_name', :string])
expect(columns).to include(['photo_content_type', :string])
expect(columns).to include(['photo_file_size', :integer])
expect(columns).to include(['photo_updated_at', :datetime])
expect(columns).to include(['avatar_file_name', "varchar"])
expect(columns).to include(['avatar_content_type', "varchar"])
expect(columns).to include(['avatar_file_size', "bigint"])
expect(columns).to include(['avatar_updated_at', "datetime"])
expect(columns).to include(['photo_file_name', "varchar"])
expect(columns).to include(['photo_content_type', "varchar"])
expect(columns).to include(['photo_file_size', "bigint"])
expect(columns).to include(['photo_updated_at', "datetime"])
end
end

Expand Down Expand Up @@ -164,7 +164,7 @@
Dummy.connection.change_table :dummies do |t|
t.column :avatar_file_name, :string
t.column :avatar_content_type, :string
t.column :avatar_file_size, :integer
t.column :avatar_file_size, :bigint
t.column :avatar_updated_at, :datetime
end
end
Expand All @@ -178,12 +178,12 @@
Dummy.connection.drop_attached_file :dummies, :avatar
end

columns = Dummy.columns.map{ |column| [column.name, column.type] }
columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }

expect(columns).to_not include(['avatar_file_name', :string])
expect(columns).to_not include(['avatar_content_type', :string])
expect(columns).to_not include(['avatar_file_size', :integer])
expect(columns).to_not include(['avatar_updated_at', :datetime])
expect(columns).to_not include(['avatar_file_name', "varchar"])
expect(columns).to_not include(['avatar_content_type', "varchar"])
expect(columns).to_not include(['avatar_file_size', "bigint"])
expect(columns).to_not include(['avatar_updated_at', "datetime"])
end

it "displays a deprecation warning" do
Expand All @@ -200,12 +200,12 @@
end

it "removes the attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] }
columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }

expect(columns).to_not include(['avatar_file_name', :string])
expect(columns).to_not include(['avatar_content_type', :string])
expect(columns).to_not include(['avatar_file_size', :integer])
expect(columns).to_not include(['avatar_updated_at', :datetime])
expect(columns).to_not include(['avatar_file_name', "varchar"])
expect(columns).to_not include(['avatar_content_type', "varchar"])
expect(columns).to_not include(['avatar_file_size', "bigint"])
expect(columns).to_not include(['avatar_updated_at', "datetime"])
end
end

Expand All @@ -214,24 +214,24 @@
Dummy.connection.change_table :dummies do |t|
t.column :photo_file_name, :string
t.column :photo_content_type, :string
t.column :photo_file_size, :integer
t.column :photo_file_size, :bigint
t.column :photo_updated_at, :datetime
end

Dummy.connection.remove_attachment :dummies, :avatar, :photo
end

it "removes the attachment columns" do
columns = Dummy.columns.map{ |column| [column.name, column.type] }

expect(columns).to_not include(['avatar_file_name', :string])
expect(columns).to_not include(['avatar_content_type', :string])
expect(columns).to_not include(['avatar_file_size', :integer])
expect(columns).to_not include(['avatar_updated_at', :datetime])
expect(columns).to_not include(['photo_file_name', :string])
expect(columns).to_not include(['photo_content_type', :string])
expect(columns).to_not include(['photo_file_size', :integer])
expect(columns).to_not include(['photo_updated_at', :datetime])
columns = Dummy.columns.map{ |column| [column.name, column.sql_type] }

expect(columns).to_not include(['avatar_file_name', "varchar"])
expect(columns).to_not include(['avatar_content_type', "varchar"])
expect(columns).to_not include(['avatar_file_size', "bigint"])
expect(columns).to_not include(['avatar_updated_at', "datetime"])
expect(columns).to_not include(['photo_file_name', "varchar"])
expect(columns).to_not include(['photo_content_type', "varchar"])
expect(columns).to_not include(['photo_file_size', "bigint"])
expect(columns).to_not include(['photo_updated_at', "datetime"])
end
end

Expand Down
2 changes: 1 addition & 1 deletion spec/support/model_reconstruction.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def rebuild_model options = {}
table.column :other, :string
table.column :avatar_file_name, :string
table.column :avatar_content_type, :string
table.column :avatar_file_size, :integer
table.column :avatar_file_size, :bigint
table.column :avatar_updated_at, :datetime
table.column :avatar_fingerprint, :string
end
Expand Down

0 comments on commit 34ec355

Please sign in to comment.