Skip to content

Commit

Permalink
Range request bug code review
Browse files Browse the repository at this point in the history
Addressed code quality issues
  • Loading branch information
atruskie committed Jan 20, 2017
1 parent 02a2158 commit 1145f8f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion app/models/range_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ def response_range(info)
end_range = info[:range_end_bytes_max] if end_range > info[:range_end_bytes_max]
# e.g. bytes=0-499, max_range_size=500 => 499 - 0 + 1 = 500 > 500
if (end_range - start_range + CONVERT_INDEX_TO_LENGTH) > @max_range_size
raise StandardError.new("Range request maximum exceeded")
fail CustomErrors::BadRequestError, 'The requested range exceeded the maximum allowed.'
end
if start_range > end_range
fail CustomErrors::BadRequestError, 'The requested range specified a first byte that was greater than the last byte.'
end

return_value[:range_start_bytes].push(start_range)
Expand Down
6 changes: 3 additions & 3 deletions spec/models/range_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,15 @@

context 'special open end range case' do
# this test case comes from a real-world production bug: https://github.com/QutBioacoustics/baw-server/issues/318
# the second part of a large range request triggers a negative content length and negative gradient in the content
# range header.
# the second part of a large range request triggers a negative content length and the last part of the content
# range header to be less than the first part.


# before bug fix:
# file_size: 822281
# request: "Range: bytes 512001-"
# info[:range_start]: 512001
# info[:range_end]: 310279 <-- problem, negative range!
# info[:range_end]: 310279 <-- problem, end less than start!
# info[:response_headers]['Content-Length']: -201721 <-- problem, negative range!
it 'should succeed with: [single range] special test case, open range greater than max range size' do
mock_request.headers[RangeRequest::HTTP_HEADER_RANGE] = 'bytes=512001-'
Expand Down

0 comments on commit 1145f8f

Please sign in to comment.