From dd3e912731eb5573bbbe376dea8f84b8bb8dc11c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20B=C3=BCnger?= Date: Tue, 7 Aug 2018 18:37:21 +0200 Subject: [PATCH] fs/OpenOptions: Make FixRangeOption clamp range to filesize. --- fs/options.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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 + } } } }