Verified Commit 5bcb7794 authored by Dominik Menke's avatar Dominik Menke Committed by GitLab
Browse files

fix(s3): fix panic in Stat() call

parent e835b93c
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -568,6 +568,8 @@ func (d *driver) Writer(ctx context.Context, path string, appendParam bool) (sto
	return d.newWriter(key, *mpUpload.UploadId, allParts), nil
}

var errUnusableHeadObjectResponse = errors.New("HeadObject returned unusable response")

func (d *driver) statHead(ctx context.Context, path string) (*storagedriver.FileInfoFields, error) {
	// NOTE(prozlach): This is to cover for the cases when the rootDirectory of
	// the driver is either "" or "/".
@@ -586,6 +588,13 @@ func (d *driver) statHead(ctx context.Context, path string) (*storagedriver.File
	if err != nil {
		return nil, err
	}

	// Some S3 implementations return an empty response for certain keys.
	// The sentinal error signals the caller to retry with a ListBucket.
	if resp.ContentLength == nil && resp.LastModified == nil {
		return nil, errUnusableHeadObjectResponse
	}

	return &storagedriver.FileInfoFields{
		Path:    path,
		IsDir:   false,
@@ -693,7 +702,10 @@ func (d *driver) Stat(ctx context.Context, path string) (storagedriver.FileInfo,
		// error if querying a key which doesn't exist or a key which has
		// nested keys and Forbidden if IAM/ACL permissions do not allow Head
		// but allow List.
		if errors.As(err, new(smithy.APIError)) {
		//
		// If the response is unusable (due to bugs in alternative S3
		// implementations), we also fail over to ListObjects.
		if errors.As(err, new(smithy.APIError)) || errors.Is(err, errUnusableHeadObjectResponse) {
			fi, err := d.statList(ctx, path)
			if err != nil {
				return nil, parseError(path, err)