mirror of
https://github.com/ipfs/kubo.git
synced 2026-03-01 06:17:56 +08:00
Merge pull request #6847 from ipfs/fix/6765
fix: fix a potential out of bounds issue in fuse
This commit is contained in:
commit
8e0f92b69e
@ -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
|
||||
}
|
||||
@ -287,10 +289,3 @@ type roNode interface {
|
||||
}
|
||||
|
||||
var _ roNode = (*Node)(nil)
|
||||
|
||||
func min(a, b int) int {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user