Skip to content

Commit

Permalink
fix: fix a potential out of bounds issue in fuse
Browse files Browse the repository at this point in the history
We likely encountered a file that misreported its size. That or there was no bug
here and we hit an issue somewhere else. Regardless, there's no reason not to
simplify this code and this should fix the issue.

fixes #6765
  • Loading branch information
Stebalien committed Jan 28, 2020
1 parent e8f7f0a commit 0a2a90e
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions fuse/readonly/readonly_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,13 +257,15 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
if err != nil {
return err
}

buf := resp.Data[:min(req.Size, int(int64(r.Size())-req.Offset))]
// Data has a capacity of Size
buf := resp.Data[:int(req.Size)]
n, err := io.ReadFull(r, buf)
if err != nil && err != io.EOF {
resp.Data = buf[:n]
switch err {
case nil, io.EOF, io.ErrUnexpectedEOF:
default:
return err
}
resp.Data = resp.Data[:n]
lm["res_size"] = n
return nil // may be non-nil / not succeeded
}
Expand All @@ -287,10 +289,3 @@ type roNode interface {
}

var _ roNode = (*Node)(nil)

func min(a, b int) int {
if a < b {
return a
}
return b
}

0 comments on commit 0a2a90e

Please sign in to comment.