@cryptotaxi247 / kubo / commits / 41aaf745a

fix: fix a potential out of bounds issue in fuse

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.

Steven Allen committed Jan 27, 2020 at 19:49 UTC 41aaf745ad8a4d4be7129fd4f8ea2cdc5521c4e4
1 file changed +6 -11
fuse/readonly/readonly_unix.go
+6 -11
@@ -257,13 +257,15 @@ func (s *Node) Read(ctx context.Context, req *fuse.ReadRequest, resp *fuse.ReadR
257 if err != nil {
258 return err
259 }
260 -
261 - buf := resp.Data[:min(req.Size, int(int64(r.Size())-req.Offset))]
260 + // Data has a capacity of Size
261 + buf := resp.Data[:int(req.Size)]
262 n, err := io.ReadFull(r, buf)
263 - if err != nil && err != io.EOF {
263 + resp.Data = buf[:n]
264 + switch err {
265 + case nil, io.EOF, io.ErrUnexpectedEOF:
266 + default:
267 return err
268 }
266 - resp.Data = resp.Data[:n]
269 lm["res_size"] = n
270 return nil // may be non-nil / not succeeded
271 }
@@ -287,10 +289,3 @@ type roNode interface {
289 }
290
291 var _ roNode = (*Node)(nil)
290 -
291 -func min(a, b int) int {
292 - if a < b {
293 - return a
294 - }
295 - return b
296 -}