-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix range header bounds check in SetRange() #674
Conversation
request-headers.go
Outdated
@@ -89,17 +89,18 @@ func (c RequestHeaders) SetRange(start, end int64) error { | |||
case start > 0 && end == 0: | |||
// Read everything starting from offset 'start'. `bytes=N-` | |||
c.Set("Range", fmt.Sprintf("bytes=%d-", start)) | |||
case start > 0 && end > 0 && end >= start: | |||
case start > 0 && end >= start: | |||
// Read everything starting at 'start' till the 'end'. `bytes=N-M` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this still retun an error if start is 0 and end > 0 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Made another attempt to fix it.
a956f8a
to
02a9a1c
Compare
request-headers.go
Outdated
c.Set("Range", fmt.Sprintf("bytes=%d", end)) | ||
case start > 0 && end == 0: | ||
// Read everything starting from offset 'start'. `bytes=N-` | ||
c.Set("Range", fmt.Sprintf("bytes=%d-", start)) | ||
case start > 0 && end > 0 && end >= start: | ||
case start >= 0 && end >= start: | ||
// Read everything starting at 'start' till the 'end'. `bytes=N-M` | ||
c.Set("Range", fmt.Sprintf("bytes=%d-%d", start, end)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test if 0-0 indeed reads the whole object?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not.
There are two conflicting cases here:
|
If we implement in the opposite way, then:
However, we lose the ability to express "read 1 byte starting from byte 0". So I chose to go with the approach in the previous comment. Still a better |
c.Set("Range", fmt.Sprintf("bytes=%d-", start)) | ||
case start > 0 && end > 0 && end >= start: | ||
// Read everything starting at 'start' till the 'end'. `bytes=N-M` | ||
case 0 <= start && start <= end: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good, can you add some tests for this as well? @donatello
This is good serves the purpose here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested with Mint, all green again. If this PR has been merged, I'll bump Minio server with this version.
@harshavardhana Tests added. |
@@ -0,0 +1,40 @@ | |||
package minio |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add license header..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Also adds tests
Should fix minio/minio#4243