0
0
Fork 0

Check Content-Length in ResponseWithLimitAdapter (#31285)

This commit is contained in:
Christian Schmidt 2024-08-06 10:23:48 +02:00 committed by GitHub
parent 103e544cfa
commit 9d0cafd06b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 107 additions and 9 deletions

View file

@ -16,6 +16,8 @@ module Paperclip
private
def cache_current_values
@target.response.require_limit_not_exceeded!(@target.limit)
@original_filename = truncated_filename
@tempfile = copy_to_tempfile(@target)
@content_type = ContentTypeDetector.new(@tempfile.path).detect
@ -27,16 +29,15 @@ module Paperclip
source.response.body.each do |chunk|
bytes_read += chunk.bytesize
raise Mastodon::LengthValidationError, "Body size exceeds limit of #{source.limit}" if bytes_read > source.limit
destination.write(chunk)
chunk.clear
raise Mastodon::LengthValidationError if bytes_read > source.limit
end
destination.rewind
destination
rescue Mastodon::LengthValidationError
rescue
destination.close(true)
raise
ensure