Skip to content
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

s3ng fix missing blob error message #3341

Merged
merged 3 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/unreleased/s3ng-download-validation.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Bugfix: validate s3ng downloads

The s3ng download func now returns an error in cases where the requested node blob is unknown
or the blob size does not match the node meta blob size.

https://github.com/cs3org/reva/pull/3341
19 changes: 19 additions & 0 deletions internal/http/services/owncloud/ocdav/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,25 @@ func (s *svc) handleGet(ctx context.Context, w http.ResponseWriter, r *http.Requ
return
}

sReq := &provider.StatRequest{
Ref: ref,
}
sRes, err := client.Stat(ctx, sReq)
if err != nil {
log.Error().Err(err).Msg("error stat resource")
w.WriteHeader(http.StatusInternalServerError)
return
} else if sRes.Status.Code != rpc.Code_CODE_OK {
errors.HandleErrorStatus(&log, w, sRes.Status)
return
}

if sRes.Info.Type != provider.ResourceType_RESOURCE_TYPE_FILE {
w.Header().Set("Content-Length", "0")
w.WriteHeader(http.StatusOK)
return
}

dReq := &provider.InitiateFileDownloadRequest{Ref: ref}
dRes, err := client.InitiateFileDownload(ctx, dReq)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/rhttp/datatx/utils/download/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func GetOrHeadFile(w http.ResponseWriter, r *http.Request, fs storage.FS, spaceI
var c int64
c, err = io.CopyN(w, sendContent, sendSize)
if err != nil {
sublog.Error().Err(err).Msg("error copying data to response")
sublog.Error().Err(err).Interface("resourceid", md.Id).Msg("error copying data to response")
return
}
if c != sendSize {
Expand Down
11 changes: 11 additions & 0 deletions pkg/storage/fs/s3ng/blobstore/blobstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package blobstore

import (
"context"
"fmt"
"io"
"net/url"
"os"
Expand Down Expand Up @@ -87,6 +88,16 @@ func (bs *Blobstore) Download(node *node.Node) (io.ReadCloser, error) {
if err != nil {
return nil, errors.Wrapf(err, "could not download object '%s' from bucket '%s'", bs.path(node), bs.bucket)
}

stat, err := reader.Stat()
if err != nil {
return nil, errors.Wrapf(err, "blob path: %s", bs.path(node))
}

if node.Blobsize != stat.Size {
return nil, fmt.Errorf("blob has unexpected size. %d bytes expected, got %d bytes", node.Blobsize, stat.Size)
}

return reader, nil
}

Expand Down