Skip to content

Commit

Permalink
Merge pull request #58 from mhoglan/nil-key-request
Browse files Browse the repository at this point in the history
* nil-key-request:
  add nil path test
  Add guard to handle if all chunks are read Add guard to handle if bytesRead is greater than content-length.  Should not occur as golang uses a LimitedReader up to the content-length, but if for some reason the bytesRead was greater than content-length, the getter will hang as it keeps trying to read the nextChunk (which does not exist)
  Fix OBOE when comparing cIdx and rChunk.size Remove the -1 occurring when checking if the current index (cIdx) was equal or greater than size of chunk (rChunk.size) being processed.  Both values are 1-based and there should not be the need to offset the size by 1;  cIdx starts at 0 initially, but is replaced by number of bytes read which is 1-based as it is a count and not an index into the range of bytes being read.
  Added guard protections for requests / responses Add guard to handle if nil path is requested Add guard to handle if content-length from response is -1 which represents that the response is chunked transfer encoding or EOF close response
  • Loading branch information
rlmcpherson committed Mar 9, 2015
2 parents 3981d2a + ee13edc commit d31b064
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ func newGetter(getURL url.URL, c *Config, b *Bucket) (io.ReadCloser, http.Header
if resp.StatusCode != 200 {
return nil, nil, newRespError(resp)
}

// Golang changes content-length to -1 when chunked transfer encoding / EOF close response detected
if resp.ContentLength == -1 {
return nil, nil, fmt.Errorf("Retrieving objects with undefined content-length " +
" responses (chunked transfer encoding / EOF close) is not supported")
}

g.contentLen = resp.ContentLength
g.chunkTotal = int((g.contentLen + g.bufsz - 1) / g.bufsz) // round up, integer division
logger.debugPrintf("object size: %3.2g MB", float64(g.contentLen)/float64((1*mb)))
Expand Down
4 changes: 4 additions & 0 deletions s3gof3r.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package s3gof3r

import (
"errors"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -84,6 +85,9 @@ func (s3 *S3) Bucket(name string) *Bucket {
// Header data from the downloaded object is also returned, useful for reading object metadata.
// DefaultConfig is used if c is nil
func (b *Bucket) GetReader(path string, c *Config) (r io.ReadCloser, h http.Header, err error) {
if path == "" {
return nil, nil, errors.New("empty path requested")
}
if c == nil {
c = b.conf()
}
Expand Down
1 change: 1 addition & 0 deletions s3gof3r_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func TestGetReader(t *testing.T) {
{"t1.test", nil, 1 * kb, nil},
{"no-md5", &Config{Scheme: "https", Client: ClientWithTimeout(clientTimeout), Md5Check: false}, 1, nil},
{"NoKey", nil, -1, &RespError{StatusCode: 404, Message: "The specified key does not exist."}},
{"", nil, -1, fmt.Errorf("empty path requested")},
{"6_mb_test",
&Config{Concurrency: 3, PartSize: 1 * mb, NTry: 2, Md5Check: true, Scheme: "https", Client: ClientWithTimeout(3 * time.Second)},
6 * mb,
Expand Down

0 comments on commit d31b064

Please sign in to comment.