diff --git a/fs/operations/operations.go b/fs/operations/operations.go index 97f82068f..773fa68be 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -1367,7 +1367,7 @@ func catObject(ctx context.Context, o fs.Object, w io.Writer, offset, count int6 opt := fs.RangeOption{Start: offset, End: -1} size := o.Size() if opt.Start < 0 && size >= 0 { - opt.Start += size + opt.Start = max(opt.Start+size, 0) } if count >= 0 { opt.End = opt.Start + count - 1 diff --git a/fs/operations/operations_test.go b/fs/operations/operations_test.go index b5057170f..cdff1fbc9 100644 --- a/fs/operations/operations_test.go +++ b/fs/operations/operations_test.go @@ -636,6 +636,8 @@ func TestCat(t *testing.T) { {0, 5, "", "ABCDE", "01234"}, {-3, -1, "", "HIJ", "678"}, {1, 3, "", "BCD", "123"}, + {-10, 3, "", "ABC", "012"}, + {-12, 5, "", "ABCDE", "01234"}, {0, -1, "\n", "ABCDEFGHIJ", "012345678"}, } { var buf bytes.Buffer