Unverified Commit 8e0f92b6 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #6847 from ipfs/fix/6765

fix: fix a potential out of bounds issue in fuse
parents e8f7f0a5 41aaf745
...@@ -257,13 +257,15 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR ...@@ -257,13 +257,15 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
if err != nil { if err != nil {
return err return err
} }
// Data has a capacity of Size
buf := resp.Data[:min(req.Size, int(int64(r.Size())-req.Offset))] buf := resp.Data[:int(req.Size)]
n, err := io.ReadFull(r, buf) 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 return err
} }
resp.Data = resp.Data[:n]
lm["res_size"] = n lm["res_size"] = n
return nil // may be non-nil / not succeeded return nil // may be non-nil / not succeeded
} }
...@@ -287,10 +289,3 @@ type roNode interface { ...@@ -287,10 +289,3 @@ type roNode interface {
} }
var _ roNode = (*Node)(nil) var _ roNode = (*Node)(nil)
func min(a, b int) int {
if a < b {
return a
}
return b
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment