From e735d312f4af94d988670929de9583dfcc40c168 Mon Sep 17 00:00:00 2001 From: Philip Peterson Date: Sun, 10 Jul 2022 22:40:16 -0400 Subject: [PATCH 1/3] Removed unused type --- modules/lfs/content_store.go | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/modules/lfs/content_store.go b/modules/lfs/content_store.go index c794a1feccc6f..0eedf4de1798b 100644 --- a/modules/lfs/content_store.go +++ b/modules/lfs/content_store.go @@ -8,7 +8,6 @@ import ( "crypto/sha256" "encoding/hex" "errors" - "fmt" "hash" "io" "os" @@ -24,21 +23,6 @@ var ( ErrSizeMismatch = errors.New("Content size does not match") ) -// ErrRangeNotSatisfiable represents an error which request range is not satisfiable. -type ErrRangeNotSatisfiable struct { - FromByte int64 -} - -// IsErrRangeNotSatisfiable returns true if the error is an ErrRangeNotSatisfiable -func IsErrRangeNotSatisfiable(err error) bool { - _, ok := err.(ErrRangeNotSatisfiable) - return ok -} - -func (err ErrRangeNotSatisfiable) Error() string { - return fmt.Sprintf("Requested range %d is not satisfiable", err.FromByte) -} - // ContentStore provides a simple file system based storage. type ContentStore struct { storage.ObjectStorage From 09af7a647cae3dfda0707c61a93600232cc4dcc3 Mon Sep 17 00:00:00 2001 From: Philip Peterson Date: Sun, 10 Jul 2022 22:40:33 -0400 Subject: [PATCH 2/3] Error if end of range is out of bounds --- services/lfs/server.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/services/lfs/server.go b/services/lfs/server.go index b868db39dbece..80b6ee01562cf 100644 --- a/services/lfs/server.go +++ b/services/lfs/server.go @@ -131,6 +131,21 @@ func DownloadHandler(ctx *context.Context) { } } + stat, err := content.Stat() + if err != nil { + log.Error("Unable to stat LFS OID[%s]. Error: %v", meta.Oid, err) + + writeStatus(ctx, http.StatusInternalServerError) + return + } + + if toByte+1 > stat.Size() { + log.Error("Whilst trying to read LFS OID[%s]: Unable to read to %d Error: %v", meta.Oid, toByte, err) + + writeStatus(ctx, http.StatusRequestedRangeNotSatisfiable) + return + } + contentLength := toByte + 1 - fromByte ctx.Resp.Header().Set("Content-Length", strconv.FormatInt(contentLength, 10)) ctx.Resp.Header().Set("Content-Type", "application/octet-stream") From c42b195850ecfa07ec9657f683124bb0b13dcc58 Mon Sep 17 00:00:00 2001 From: Philip Peterson Date: Sun, 24 Jul 2022 20:14:54 -0400 Subject: [PATCH 3/3] Remove check --- services/lfs/server.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/services/lfs/server.go b/services/lfs/server.go index 80b6ee01562cf..b868db39dbece 100644 --- a/services/lfs/server.go +++ b/services/lfs/server.go @@ -131,21 +131,6 @@ func DownloadHandler(ctx *context.Context) { } } - stat, err := content.Stat() - if err != nil { - log.Error("Unable to stat LFS OID[%s]. Error: %v", meta.Oid, err) - - writeStatus(ctx, http.StatusInternalServerError) - return - } - - if toByte+1 > stat.Size() { - log.Error("Whilst trying to read LFS OID[%s]: Unable to read to %d Error: %v", meta.Oid, toByte, err) - - writeStatus(ctx, http.StatusRequestedRangeNotSatisfiable) - return - } - contentLength := toByte + 1 - fromByte ctx.Resp.Header().Set("Content-Length", strconv.FormatInt(contentLength, 10)) ctx.Resp.Header().Set("Content-Type", "application/octet-stream")