Skip to content

Commit

Permalink
Fix multipart parser for large files rack#1308
Browse files Browse the repository at this point in the history
  • Loading branch information
aiomaster committed Oct 23, 2018
1 parent 5559676 commit 4ead482
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/rack/multipart/parser.rb
Expand Up @@ -182,7 +182,7 @@ def initialize(boundary, tempfile, bufsize, query_parser)
@collector = Collector.new tempfile

@sbuf = StringScanner.new("".dup)
@body_regex = /(.*?)(#{EOL})?#{Regexp.quote(@boundary)}(#{EOL}|--)/m
@body_regex = /(?:#{EOL})?#{Regexp.quote(@boundary)}(?:#{EOL}|--)/m
@rx_max_size = EOL.size + @boundary.bytesize + [EOL.size, '--'.size].max
@head_regex = /(.*?#{EOL})#{EOL}/m
end
Expand Down Expand Up @@ -265,8 +265,8 @@ def handle_mime_head
end

def handle_mime_body
if @sbuf.check_until(@body_regex) # check but do not advance the pointer yet
body = @sbuf[1]
if (body_with_boundary = @sbuf.check_until(@body_regex)) # check but do not advance the pointer yet
body = body_with_boundary.sub(/#{@body_regex}\z/m, '') # remove the boundary from the string
@collector.on_mime_body @mime_index, body
@sbuf.pos += body.length + 2 # skip \r\n after the content
@state = :CONSUME_TOKEN
Expand Down

0 comments on commit 4ead482

Please sign in to comment.