Skip to content

Commit 0cf2c1a

Browse files
committed
fix: ensure_integrity_of nil guard
Add `nil` check before `.data` access; raises `FileNotFoundError` if record missing.
1 parent efccd23 commit 0cf2c1a

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

lib/active_storage/service/db_service.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def download_chunk(key, range)
5151
size = range.size
5252
args = adapter_sqlserver? || adapter_sqlite? ? "data, #{from}, #{size}" : "data FROM #{from} FOR #{size}"
5353
record = object_for(key, fields: "SUBSTRING(#{args}) AS chunk")
54-
raise(ActiveStorage::FileNotFoundError) unless record
54+
raise ActiveStorage::FileNotFoundError unless record
5555

5656
record.chunk
5757
end
@@ -160,15 +160,18 @@ def generate_url(key, expires_in:, filename:, content_type:, disposition:)
160160
end
161161

162162
def ensure_integrity_of(key, checksum)
163-
return if Digest::MD5.base64digest(object_for(key).data) == checksum
163+
record = object_for(key)
164+
raise ActiveStorage::FileNotFoundError unless record
165+
166+
return if Digest::MD5.base64digest(record.data) == checksum
164167

165168
delete(key)
166169
raise ActiveStorage::IntegrityError
167170
end
168171

169172
def retrieve_file(key)
170173
file = object_for(key)
171-
raise(ActiveStorage::FileNotFoundError) unless file
174+
raise ActiveStorage::FileNotFoundError unless file
172175

173176
file.data
174177
end

0 commit comments

Comments
 (0)