Skip to content

Commit

Permalink
storage/minio: add workaround for unspecified size in Save when multi…
Browse files Browse the repository at this point in the history
…part is disabled
  • Loading branch information
stevefan1999-personal committed Nov 11, 2022
1 parent c71fa9b commit 866f567
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions modules/storage/minio.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package storage

import (
"bytes"
"context"
"io"
"net/url"
Expand Down Expand Up @@ -141,6 +142,22 @@ func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error)
disableSignature, disableMultipart = m.config.DisableSignature, m.config.DisableMultipart
}

if disableMultipart && size < 0 {
// Attempts to read everything from the source into memory. This can take a big toll on memory, and it can become a potential DoS source
// but since we have disabled multipart upload this mean we can't really stream write anymore...
// well, unless we have a better way to estimate the stream size, this would be a workaround

buf := &bytes.Buffer{}
if n, err := io.Copy(buf, r); err != nil {
// I guess this would likely be EOF or OOM...?
return -1, err
} else {
// Since we read all the data from the source, it might not be usable again,
// so we should swap the reader location to our memory buffer
r, size = buf, n
}
}

uploadInfo, err := m.client.PutObject(
m.ctx,
m.bucket,
Expand Down

0 comments on commit 866f567

Please sign in to comment.