diff options
author | KN4CK3R <KN4CK3R@users.noreply.github.com> | 2021-04-06 15:22:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-06 21:22:34 +0800 |
commit | 5f18404045f1979fab34583277ad2a1bfab81ed9 (patch) | |
tree | fcb23d5303749901dbda0e9c67d198425beabfdf /modules/lfs/server.go | |
parent | 1ba8b95eb472c5ec089ac947acdf822457d33378 (diff) | |
download | gitea-5f18404045f1979fab34583277ad2a1bfab81ed9.tar.gz gitea-5f18404045f1979fab34583277ad2a1bfab81ed9.zip |
Close file on invalid range (Addition to #15166) (#15268)
* Close file on invalid range.
* Close on seek error
Signed-off-by: Andrew Thornton <art27@cantab.net>
* Moved 'Seek' into server.
* io.ReadSeekCloser is only available in Go 1.16
Co-authored-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Lauris BH <lauris@nix.lv>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'modules/lfs/server.go')
-rw-r--r-- | modules/lfs/server.go | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/modules/lfs/server.go b/modules/lfs/server.go index 45cba9d9b7..f45423b851 100644 --- a/modules/lfs/server.go +++ b/modules/lfs/server.go @@ -175,6 +175,11 @@ func getContentHandler(ctx *context.Context) { statusCode = 206 fromByte, _ = strconv.ParseInt(match[1], 10, 32) + if fromByte >= meta.Size { + writeStatus(ctx, http.StatusRequestedRangeNotSatisfiable) + return + } + if match[2] != "" { _toByte, _ := strconv.ParseInt(match[2], 10, 32) if _toByte >= fromByte && _toByte < toByte { @@ -188,18 +193,24 @@ func getContentHandler(ctx *context.Context) { } contentStore := &ContentStore{ObjectStorage: storage.LFS} - content, err := contentStore.Get(meta, fromByte) + content, err := contentStore.Get(meta) if err != nil { - if IsErrRangeNotSatisfiable(err) { - writeStatus(ctx, http.StatusRequestedRangeNotSatisfiable) - } else { - // Errors are logged in contentStore.Get - writeStatus(ctx, 404) - } + // Errors are logged in contentStore.Get + writeStatus(ctx, http.StatusNotFound) return } defer content.Close() + if fromByte > 0 { + _, err = content.Seek(fromByte, io.SeekStart) + if err != nil { + log.Error("Whilst trying to read LFS OID[%s]: Unable to seek to %d Error: %v", meta.Oid, fromByte, err) + + writeStatus(ctx, http.StatusInternalServerError) + return + } + } + contentLength := toByte + 1 - fromByte ctx.Resp.Header().Set("Content-Length", strconv.FormatInt(contentLength, 10)) ctx.Resp.Header().Set("Content-Type", "application/octet-stream") |