Skip to content

Commit

Permalink
fuse: fix copied bytes overflow (#5565)
Browse files Browse the repository at this point in the history
  • Loading branch information
davies authored and jiefenghuang committed Jan 20, 2025
1 parent 705561b commit 7a3a5c0
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion pkg/fuse/fuse.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package fuse
import (
"fmt"
"log"
"math"
"os"
"os/exec"
"runtime"
Expand Down Expand Up @@ -298,7 +299,12 @@ func (fs *fileSystem) Fallocate(cancel <-chan struct{}, in *fuse.FallocateIn) (c
func (fs *fileSystem) CopyFileRange(cancel <-chan struct{}, in *fuse.CopyFileRangeIn) (written uint32, code fuse.Status) {
ctx := fs.newContext(cancel, &in.InHeader)
defer releaseContext(ctx)
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))
var len = in.Len
if len > math.MaxUint32 {
// written may overflow
len = math.MaxUint32 + 1 - meta.ChunkSize
}
copied, err := fs.v.CopyFileRange(ctx, Ino(in.NodeId), in.FhIn, in.OffIn, Ino(in.NodeIdOut), in.FhOut, in.OffOut, len, uint32(in.Flags))
if err != 0 {
return 0, fuse.Status(err)
}
Expand Down

0 comments on commit 7a3a5c0

Please sign in to comment.