Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fs/OpenOptions: Make FixRangeOption clamp range to filesize.

Sebastian Büngerdd3e912731eb
diff --git a/fs/options.go b/fs/options.go
index dde652485..c277b1142 100644
--- a/fs/options.go
+++ b/fs/options.go
@@ -135,9 +135,9 @@ func (o *RangeOption) Decode(size int64) (offset, limit int64) {
// FixRangeOption looks through the slice of options and adjusts any
// RangeOption~s found that request a fetch from the end into an
-// absolute fetch using the size passed in. Some remotes (eg
-// Onedrive, Box) don't support range requests which index from the
-// end.
+// absolute fetch using the size passed in and makes sure the range does
+// not exceed filesize. Some remotes (eg Onedrive, Box) don't support
+// range requests which index from the end.
func FixRangeOption(options []OpenOption, size int64) {
for i := range options {
option := options[i]
@@ -147,6 +147,10 @@ func FixRangeOption(options []OpenOption, size int64) {
x = &RangeOption{Start: size - x.End, End: -1}
options[i] = x
}
+ if x.End > size {
+ x = &RangeOption{Start: x.Start, End: size}
+ options[i] = x
+ }
}
}
}