Fix an infinite loop bug
While doing recursive listing of objects and object prefixes which have non encoded characters for example ``++`` leads to S3 sending same replies for all subsequent ``ListObjects()`` request. Essentially leading to an infinite loop.
This commit is contained in:
+5
-1
@@ -54,7 +54,11 @@ func main() {
|
||||
* [StatObject(bucket, object) (ObjectStat, error)](examples/statobject.go)
|
||||
* [RemoveObject(bucket, object) error](examples/removeobject.go)
|
||||
* [DropIncompleteUpload(bucket, object) <-chan error](examples/dropincompleteuploads.go)
|
||||
* [PresignedGetObject(bucket, object, expires) (string, error)](examples/presignedgetobject.go)
|
||||
|
||||
### Presigned Bucket/Object Level
|
||||
* [PresignedGetObject(bucket, object, time.Duration) (string, error)](examples/s3/presignedgetobject.go)
|
||||
* [PresignedPutObject(bucket, object, time.Duration) (string, error)](examples/s3/presignedputobject.go)
|
||||
* [PresignedPostPolicy(NewPostPolicy()) (map[string]string, error)](examples/s3/presignedpostpolicy.go)
|
||||
|
||||
### API Reference
|
||||
|
||||
|
||||
+18
-2
@@ -266,10 +266,10 @@ func (a apiCore) listObjectsRequest(bucket, marker, prefix, delimiter string, ma
|
||||
resourceQuery := func() (*string, error) {
|
||||
switch {
|
||||
case marker != "":
|
||||
marker = fmt.Sprintf("&marker=%s", marker)
|
||||
marker = fmt.Sprintf("&marker=%s", getURLEncodedPath(marker))
|
||||
fallthrough
|
||||
case prefix != "":
|
||||
prefix = fmt.Sprintf("&prefix=%s", prefix)
|
||||
prefix = fmt.Sprintf("&prefix=%s", getURLEncodedPath(prefix))
|
||||
fallthrough
|
||||
case delimiter != "":
|
||||
delimiter = fmt.Sprintf("&delimiter=%s", delimiter)
|
||||
@@ -604,6 +604,22 @@ func (a apiCore) presignedGetObject(bucket, object string, expires, offset, leng
|
||||
return req.PreSignV2()
|
||||
}
|
||||
|
||||
func (a apiCore) presignedPutObject(bucket, object string, expires int64) (string, error) {
|
||||
if err := invalidArgumentError(object); err != nil {
|
||||
return "", err
|
||||
}
|
||||
op := &operation{
|
||||
HTTPServer: a.config.Endpoint,
|
||||
HTTPMethod: "PUT",
|
||||
HTTPPath: separator + bucket + separator + object,
|
||||
}
|
||||
req, err := newPresignedRequest(op, a.config, expires)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return req.PreSignV2()
|
||||
}
|
||||
|
||||
// getObjectRequest wrapper creates a new getObject request
|
||||
func (a apiCore) getObjectRequest(bucket, object string, offset, length int64) (*request, error) {
|
||||
op := &operation{
|
||||
|
||||
+2
-2
@@ -34,13 +34,13 @@ func (a apiCore) listMultipartUploadsRequest(bucket, keymarker, uploadIDMarker,
|
||||
resourceQuery := func() (string, error) {
|
||||
switch {
|
||||
case keymarker != "":
|
||||
keymarker = fmt.Sprintf("&key-marker=%s", keymarker)
|
||||
keymarker = fmt.Sprintf("&key-marker=%s", getURLEncodedPath(keymarker))
|
||||
fallthrough
|
||||
case uploadIDMarker != "":
|
||||
uploadIDMarker = fmt.Sprintf("&upload-id-marker=%s", uploadIDMarker)
|
||||
fallthrough
|
||||
case prefix != "":
|
||||
prefix = fmt.Sprintf("&prefix=%s", prefix)
|
||||
prefix = fmt.Sprintf("&prefix=%s", getURLEncodedPath(prefix))
|
||||
fallthrough
|
||||
case delimiter != "":
|
||||
delimiter = fmt.Sprintf("&delimiter=%s", delimiter)
|
||||
|
||||
+10
@@ -73,6 +73,7 @@ type ObjectAPI interface {
|
||||
// PresignedAPI - object specific for now
|
||||
type PresignedAPI interface {
|
||||
PresignedGetObject(bucket, object string, expires time.Duration) (string, error)
|
||||
PresignedPutObject(bucket, object string, expires time.Duration) (string, error)
|
||||
PresignedPostPolicy(*PostPolicy) (map[string]string, error)
|
||||
}
|
||||
|
||||
@@ -236,6 +237,15 @@ func (a api) PresignedPostPolicy(p *PostPolicy) (map[string]string, error) {
|
||||
|
||||
/// Expires maximum is 7days - ie. 604800 and minimum is 1
|
||||
|
||||
// PresignedPutObject get a presigned URL to retrieve an object for third party apps
|
||||
func (a api) PresignedPutObject(bucket, object string, expires time.Duration) (string, error) {
|
||||
expireSeconds := int64(expires / time.Second)
|
||||
if expireSeconds < 1 || expireSeconds > 604800 {
|
||||
return "", invalidArgumentError("")
|
||||
}
|
||||
return a.presignedPutObject(bucket, object, expireSeconds)
|
||||
}
|
||||
|
||||
// PresignedGetObject get a presigned URL to retrieve an object for third party apps
|
||||
func (a api) PresignedGetObject(bucket, object string, expires time.Duration) (string, error) {
|
||||
expireSeconds := int64(expires / time.Second)
|
||||
|
||||
+1
-1
@@ -306,7 +306,7 @@ func (r *request) PreSignV2() (string, error) {
|
||||
r.Set("Date", d.Format(http.TimeFormat))
|
||||
}
|
||||
epochExpires := d.Unix() + r.expires
|
||||
signText := fmt.Sprintf("GET\n\n\n%d\n%s", epochExpires, r.req.URL.Path)
|
||||
signText := fmt.Sprintf("%s\n\n\n%d\n%s", r.req.Method, epochExpires, r.req.URL.Path)
|
||||
hm := hmac.New(sha1.New, []byte(r.config.SecretAccessKey))
|
||||
hm.Write([]byte(signText))
|
||||
|
||||
|
||||
+6
-1
@@ -55,6 +55,11 @@ func main() {
|
||||
* [StatObject(bucket, object) (ObjectStat, error)](examples/s3/statobject.go)
|
||||
* [RemoveObject(bucket, object) error](examples/s3/removeobject.go)
|
||||
|
||||
### Presigned Bucket/Object Level
|
||||
* [PresignedGetObject(bucket, object, time.Duration) (string, error)](examples/s3/presignedgetobject.go)
|
||||
* [PresignedPutObject(bucket, object, time.Duration) (string, error)](examples/s3/presignedputobject.go)
|
||||
* [PresignedPostPolicy(NewPostPolicy()) (map[string]string, error)](examples/s3/presignedpostpolicy.go)
|
||||
|
||||
### API Reference
|
||||
|
||||
[](http://godoc.org/github.com/minio/minio-go)
|
||||
@@ -63,4 +68,4 @@ func main() {
|
||||
|
||||
[Contributors Guide](./CONTRIBUTING.md)
|
||||
|
||||
[](https://travis-ci.org/minio/minio-go) [](https://ci.appveyor.com/project/harshavardhana/minio-go)
|
||||
[](https://travis-ci.org/minio/minio-go) [](https://ci.appveyor.com/project/harshavardhana/minio-go)
|
||||
|
||||
+15
-2
@@ -266,10 +266,10 @@ func (a apiCore) listObjectsRequest(bucket, marker, prefix, delimiter string, ma
|
||||
resourceQuery := func() (*string, error) {
|
||||
switch {
|
||||
case marker != "":
|
||||
marker = fmt.Sprintf("&marker=%s", marker)
|
||||
marker = fmt.Sprintf("&marker=%s", getURLEncodedPath(marker))
|
||||
fallthrough
|
||||
case prefix != "":
|
||||
prefix = fmt.Sprintf("&prefix=%s", prefix)
|
||||
prefix = fmt.Sprintf("&prefix=%s", getURLEncodedPath(prefix))
|
||||
fallthrough
|
||||
case delimiter != "":
|
||||
delimiter = fmt.Sprintf("&delimiter=%s", delimiter)
|
||||
@@ -578,6 +578,19 @@ func (a apiCore) presignedPostPolicy(p *PostPolicy) map[string]string {
|
||||
return p.formData
|
||||
}
|
||||
|
||||
func (a apiCore) presignedPutObject(bucket, object string, expires int64) (string, error) {
|
||||
op := &operation{
|
||||
HTTPServer: a.config.Endpoint,
|
||||
HTTPMethod: "PUT",
|
||||
HTTPPath: separator + bucket + separator + object,
|
||||
}
|
||||
r, err := newPresignedRequest(op, a.config, strconv.FormatInt(expires, 10))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return r.PreSignV4()
|
||||
}
|
||||
|
||||
func (a apiCore) presignedGetObjectRequest(bucket, object string, expires, offset, length int64) (*request, error) {
|
||||
op := &operation{
|
||||
HTTPServer: a.config.Endpoint,
|
||||
|
||||
+2
-2
@@ -34,13 +34,13 @@ func (a apiCore) listMultipartUploadsRequest(bucket, keymarker, uploadIDMarker,
|
||||
resourceQuery := func() (string, error) {
|
||||
switch {
|
||||
case keymarker != "":
|
||||
keymarker = fmt.Sprintf("&key-marker=%s", keymarker)
|
||||
keymarker = fmt.Sprintf("&key-marker=%s", getURLEncodedPath(keymarker))
|
||||
fallthrough
|
||||
case uploadIDMarker != "":
|
||||
uploadIDMarker = fmt.Sprintf("&upload-id-marker=%s", uploadIDMarker)
|
||||
fallthrough
|
||||
case prefix != "":
|
||||
prefix = fmt.Sprintf("&prefix=%s", prefix)
|
||||
prefix = fmt.Sprintf("&prefix=%s", getURLEncodedPath(prefix))
|
||||
fallthrough
|
||||
case delimiter != "":
|
||||
delimiter = fmt.Sprintf("&delimiter=%s", delimiter)
|
||||
|
||||
+10
@@ -73,6 +73,7 @@ type ObjectAPI interface {
|
||||
// PresignedAPI - object specific for now
|
||||
type PresignedAPI interface {
|
||||
PresignedGetObject(bucket, object string, expires time.Duration) (string, error)
|
||||
PresignedPutObject(bucket, object string, expires time.Duration) (string, error)
|
||||
PresignedPostPolicy(*PostPolicy) (map[string]string, error)
|
||||
}
|
||||
|
||||
@@ -223,6 +224,15 @@ func New(config Config) (API, error) {
|
||||
|
||||
/// Expires maximum is 7days - ie. 604800 and minimum is 1
|
||||
|
||||
// PresignedPutObject get a presigned URL to upload an object
|
||||
func (a api) PresignedPutObject(bucket, object string, expires time.Duration) (string, error) {
|
||||
expireSeconds := int64(expires / time.Second)
|
||||
if expireSeconds < 1 || expireSeconds > 604800 {
|
||||
return "", invalidArgumentError("")
|
||||
}
|
||||
return a.presignedPutObject(bucket, object, expireSeconds)
|
||||
}
|
||||
|
||||
// PresignedGetObject get a presigned URL to retrieve an object for third party apps
|
||||
func (a api) PresignedGetObject(bucket, object string, expires time.Duration) (string, error) {
|
||||
expireSeconds := int64(expires / time.Second)
|
||||
|
||||
Reference in New Issue
Block a user