Skip to content

Commit

Permalink
Merge pull request #554 from restic/debug-fuse-panic
Browse files Browse the repository at this point in the history
Fix fuse panic with empty files
  • Loading branch information
fd0 committed Jul 29, 2016
2 parents e575494 + 8418fed commit 959df5c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/restic/fuse/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package fuse

import (
"errors"
"sync"

"restic"
Expand Down Expand Up @@ -120,9 +121,21 @@ 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

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")
}

// 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]) {
Expand Down

0 comments on commit 959df5c

Please sign in to comment.