Skip to content

Commit 866f567

Browse files
storage/minio: add workaround for unspecified size in Save when multipart is disabled
1 parent c71fa9b commit 866f567

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

modules/storage/minio.go

+17
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package storage
66

77
import (
8+
"bytes"
89
"context"
910
"io"
1011
"net/url"
@@ -141,6 +142,22 @@ func (m *MinioStorage) Save(path string, r io.Reader, size int64) (int64, error)
141142
disableSignature, disableMultipart = m.config.DisableSignature, m.config.DisableMultipart
142143
}
143144

145+
if disableMultipart && size < 0 {
146+
// 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
147+
// but since we have disabled multipart upload this mean we can't really stream write anymore...
148+
// well, unless we have a better way to estimate the stream size, this would be a workaround
149+
150+
buf := &bytes.Buffer{}
151+
if n, err := io.Copy(buf, r); err != nil {
152+
// I guess this would likely be EOF or OOM...?
153+
return -1, err
154+
} else {
155+
// Since we read all the data from the source, it might not be usable again,
156+
// so we should swap the reader location to our memory buffer
157+
r, size = buf, n
158+
}
159+
}
160+
144161
uploadInfo, err := m.client.PutObject(
145162
m.ctx,
146163
m.bucket,

0 commit comments

Comments
 (0)