Skip to content

Commit

Permalink
Fix ReDoS in Rack::Utils.get_byte_ranges
Browse files Browse the repository at this point in the history
This commit fixes a ReDoS problem in `get_byte_ranges`.  Thanks
@ooooooo_q for the patch!

[CVE-2022-44570]
  • Loading branch information
tenderlove committed Jan 17, 2023
1 parent a493640 commit 7a9d76a
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/rack/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,17 +426,18 @@ def get_byte_ranges(http_range, size)
return nil unless http_range && http_range =~ /bytes=([^;]+)/
ranges = []
$1.split(/,\s*/).each do |range_spec|
return nil unless range_spec =~ /(\d*)-(\d*)/
r0, r1 = $1, $2
if r0.empty?
return nil if r1.empty?
return nil unless range_spec.include?('-')
range = range_spec.split('-')
r0, r1 = range[0], range[1]
if r0.nil? || r0.empty?
return nil if r1.nil?
# suffix-byte-range-spec, represents trailing suffix of file
r0 = size - r1.to_i
r0 = 0 if r0 < 0
r1 = size - 1
else
r0 = r0.to_i
if r1.empty?
if r1.nil?
r1 = size - 1
else
r1 = r1.to_i
Expand Down

0 comments on commit 7a9d76a

Please sign in to comment.