aboutsummaryrefslogtreecommitdiff
path: root/mediaapi/routing/upload.go
diff options
context:
space:
mode:
authorS7evinK <tfaelligen@gmail.com>2021-07-19 18:58:51 +0200
committerGitHub <noreply@github.com>2021-07-19 17:58:51 +0100
commit5094bc89bf9f7f34fa66be3b40379b0056d7758e (patch)
treef2e478ce3e223599b758fc1dbe8f16d10206c8c4 /mediaapi/routing/upload.go
parent09d3bab8380fd59f855d05ea743062b52fca4045 (diff)
Set MaxFileSizeBytes <= 0 to unlimited (#1876)
* Revert "Set MaxFileSizeBytes <= 0 to "unlimited" (#1875)" This reverts commit 9ed044042156a9bdfafb4ae9830b3ed41225444e. * Actually allow unlimited upload Signed-off-by: Till Faelligen <tfaelligen@gmail.com> Co-authored-by: kegsay <kegan@matrix.org>
Diffstat (limited to 'mediaapi/routing/upload.go')
-rw-r--r--mediaapi/routing/upload.go19
1 files changed, 8 insertions, 11 deletions
diff --git a/mediaapi/routing/upload.go b/mediaapi/routing/upload.go
index bc0d206b..ecdab219 100644
--- a/mediaapi/routing/upload.go
+++ b/mediaapi/routing/upload.go
@@ -147,20 +147,17 @@ 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"),
+ if *cfg.MaxFileSizeBytes > 0 {
+ if *cfg.MaxFileSizeBytes+1 <= 0 {
+ r.Logger.WithFields(log.Fields{
+ "MaxFileSizeBytes": *cfg.MaxFileSizeBytes,
+ }).Warnf("Configured MaxFileSizeBytes overflows int64, defaulting to %d bytes", config.DefaultMaxFileSizeBytes)
+ cfg.MaxFileSizeBytes = &config.DefaultMaxFileSizeBytes
}
+ reqReader = io.LimitReader(reqReader, int64(*cfg.MaxFileSizeBytes)+1)
}
- lr := io.LimitReader(reqReader, int64(*cfg.MaxFileSizeBytes)+1)
- hash, bytesWritten, tmpDir, err := fileutils.WriteTempFile(ctx, lr, cfg.AbsBasePath)
+ hash, bytesWritten, tmpDir, err := fileutils.WriteTempFile(ctx, reqReader, cfg.AbsBasePath)
if err != nil {
r.Logger.WithError(err).WithFields(log.Fields{
"MaxFileSizeBytes": *cfg.MaxFileSizeBytes,