From 5afda94a3c987bfdbe46369d623c068f1664f18b Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 29 Jul 2016 20:55:09 +0200 Subject: [PATCH 1/3] Handle reads with large offsets --- src/restic/fuse/file.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/restic/fuse/file.go b/src/restic/fuse/file.go index 2f0db5738..02b36579c 100644 --- a/src/restic/fuse/file.go +++ b/src/restic/fuse/file.go @@ -4,6 +4,7 @@ package fuse import ( + "errors" "sync" "restic" @@ -120,9 +121,16 @@ func (f *file) getBlobAt(i int) (blob []byte, err error) { } func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadResponse) error { - debug.Log("file.Read", "Read(%v), file size %v", req.Size, f.node.Size) + debug.Log("file.Read", "Read(%v, %v, %v), file size %v", f.node.Name, req.Size, req.Offset, f.node.Size) offset := req.Offset + lastSize := f.sizes[len(f.sizes)-1] + if offset > int64(lastSize) { + debug.Log("file.Read", "Read(%v): offset is greater than file size: %v > %v, node size %v", + f.node.Name, req.Offset, lastSize, f.node.Size) + return errors.New("offset greater than files size") + } + // Skip blobs before the offset startContent := 0 for offset > int64(f.sizes[startContent]) { From 3de989b7bb39bf69fcc341f49d81f8c702163bbe Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 29 Jul 2016 21:05:36 +0200 Subject: [PATCH 2/3] Fix panic with empty files --- src/restic/fuse/file.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/restic/fuse/file.go b/src/restic/fuse/file.go index 02b36579c..27ebae705 100644 --- a/src/restic/fuse/file.go +++ b/src/restic/fuse/file.go @@ -124,10 +124,9 @@ func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR debug.Log("file.Read", "Read(%v, %v, %v), file size %v", f.node.Name, req.Size, req.Offset, f.node.Size) offset := req.Offset - lastSize := f.sizes[len(f.sizes)-1] - if offset > int64(lastSize) { - debug.Log("file.Read", "Read(%v): offset is greater than file size: %v > %v, node size %v", - f.node.Name, req.Offset, lastSize, f.node.Size) + if uint64(offset) > f.node.Size { + debug.Log("file.Read", "Read(%v): offset is greater than file size: %v > %v", + f.node.Name, req.Offset, f.node.Size) return errors.New("offset greater than files size") } From 8418fed18e84ce15bd410a1f1f81fb1c04efa89e Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Fri, 29 Jul 2016 21:18:32 +0200 Subject: [PATCH 3/3] Handle empty files correctly --- src/restic/fuse/file.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/restic/fuse/file.go b/src/restic/fuse/file.go index 27ebae705..8a4095524 100644 --- a/src/restic/fuse/file.go +++ b/src/restic/fuse/file.go @@ -130,6 +130,12 @@ func (f *file) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR return errors.New("offset greater than files size") } + // handle special case: file is empty + if f.node.Size == 0 { + resp.Data = resp.Data[:0] + return nil + } + // Skip blobs before the offset startContent := 0 for offset > int64(f.sizes[startContent]) {