Skip to content

Commit bffcba7

Browse files
daviesjiefenghuang
authored andcommitted
fuse: fix copied bytes overflow (#5565)
1 parent d020373 commit bffcba7

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

pkg/fuse/fuse.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package fuse
1818

1919
import (
2020
"fmt"
21+
"math"
2122
"os"
2223
"os/exec"
2324
"runtime"
@@ -297,7 +298,12 @@ func (fs *fileSystem) Fallocate(cancel <-chan struct{}, in *fuse.FallocateIn) (c
297298
func (fs *fileSystem) CopyFileRange(cancel <-chan struct{}, in *fuse.CopyFileRangeIn) (written uint32, code fuse.Status) {
298299
ctx := fs.newContext(cancel, &in.InHeader)
299300
defer releaseContext(ctx)
300-
copied, err := fs.v.CopyFileRange(ctx, Ino(in.NodeId), in.FhIn, in.OffIn, Ino(in.NodeIdOut), in.FhOut, in.OffOut, in.Len, uint32(in.Flags))
301+
var len = in.Len
302+
if len > math.MaxUint32 {
303+
// written may overflow
304+
len = math.MaxUint32 + 1 - meta.ChunkSize
305+
}
306+
copied, err := fs.v.CopyFileRange(ctx, Ino(in.NodeId), in.FhIn, in.OffIn, Ino(in.NodeIdOut), in.FhOut, in.OffOut, len, uint32(in.Flags))
301307
if err != 0 {
302308
return 0, fuse.Status(err)
303309
}

0 commit comments

Comments
 (0)