s3: validate CopyCutoff size before copy

Signed-off-by: hoyho <luohaihao@gmail.com>
This commit is contained in:
hoyho 2024-03-13 19:53:38 +08:00 committed by Nick Craig-Wood
parent bf494d48d6
commit a24aeba495

View File

@ -3022,6 +3022,14 @@ func (f *Fs) setUploadChunkSize(cs fs.SizeSuffix) (old fs.SizeSuffix, err error)
return
}
func checkCopyCutoff(cs fs.SizeSuffix) error {
minCopySize := fs.SizeSuffixBase
if cs < minCopySize {
return fmt.Errorf("value is too small (%v is less than %v)", cs, minCopySize)
}
return nil
}
func checkUploadCutoff(cs fs.SizeSuffix) error {
if cs > maxUploadCutoff {
return fmt.Errorf("%s is greater than %s", cs, maxUploadCutoff)
@ -3322,6 +3330,10 @@ func NewFs(ctx context.Context, name, root string, m configmap.Mapper) (fs.Fs, e
if err != nil {
return nil, fmt.Errorf("s3: upload cutoff: %w", err)
}
err = checkCopyCutoff(opt.CopyCutoff)
if err != nil {
return nil, fmt.Errorf("s3: --s3-copy-cutoff: %w", err)
}
if opt.Versions && opt.VersionAt.IsSet() {
return nil, errors.New("s3: can't use --s3-versions and --s3-version-at at the same time")
}