aboutsummaryrefslogtreecommitdiff
path: root/mediaapi
diff options
context:
space:
mode:
authorS7evinK <tfaelligen@gmail.com>2021-06-14 15:12:03 +0200
committerGitHub <noreply@github.com>2021-06-14 14:12:03 +0100
commit9ed044042156a9bdfafb4ae9830b3ed41225444e (patch)
tree7486c619495a61770a26e6cc1f08455ec0c0a767 /mediaapi
parent9633ed747d9629a838e2308530251aadc3585d4c (diff)
Set MaxFileSizeBytes <= 0 to "unlimited" (#1875)
* Set MaxFileSizeBytes < 0 to "unlimited" Signed-off-by: Till Faelligen <tfaelligen@gmail.com> * int64 overflows later in mediaapi/routing/upload.go[doUpload] * Prevent int overflow when uploading
Diffstat (limited to 'mediaapi')
-rw-r--r--mediaapi/routing/upload.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/mediaapi/routing/upload.go b/mediaapi/routing/upload.go
index ada02b11..bc0d206b 100644
--- a/mediaapi/routing/upload.go
+++ b/mediaapi/routing/upload.go
@@ -147,6 +147,18 @@ func (r *uploadRequest) doUpload(
// r.storeFileAndMetadata(ctx, tmpDir, ...)
// before you return from doUpload else we will leak a temp file. We could make this nicer with a `WithTransaction` style of
// nested function to guarantee either storage or cleanup.
+
+ // should not happen, but prevents any int overflows
+ if cfg.MaxFileSizeBytes != nil && *cfg.MaxFileSizeBytes+1 <= 0 {
+ r.Logger.WithFields(log.Fields{
+ "MaxFileSizeBytes": *cfg.MaxFileSizeBytes + 1,
+ }).Error("Error while transferring file, configured max_file_size_bytes overflows int64")
+ return &util.JSONResponse{
+ Code: http.StatusBadRequest,
+ JSON: jsonerror.Unknown("Failed to upload"),
+ }
+ }
+
lr := io.LimitReader(reqReader, int64(*cfg.MaxFileSizeBytes)+1)
hash, bytesWritten, tmpDir, err := fileutils.WriteTempFile(ctx, lr, cfg.AbsBasePath)
if err != nil {