diff --git a/pkg/meta/redis.go b/pkg/meta/redis.go index 3c09d2c442dc..c57ce268d7c6 100644 --- a/pkg/meta/redis.go +++ b/pkg/meta/redis.go @@ -949,6 +949,7 @@ func (m *redisMeta) Fallocate(ctx Context, inode Ino, mode uint8, off uint64, si _, err = tx.TxPipelined(ctx, func(pipe redis.Pipeliner) error { pipe.Set(ctx, m.inodeKey(inode), m.marshal(&t), 0) if mode&(fallocZeroRange|fallocPunchHole) != 0 && off < old { + off, size := off, size if off+size > old { size = old - off } @@ -2041,6 +2042,7 @@ func (m *redisMeta) CopyFileRange(ctx Context, fin Ino, offIn uint64, fout Ino, *copied = 0 return nil } + size := size if offIn+size > sattr.Length { size = sattr.Length - offIn } diff --git a/pkg/meta/sql.go b/pkg/meta/sql.go index 672e262781ad..7f9418a25580 100644 --- a/pkg/meta/sql.go +++ b/pkg/meta/sql.go @@ -1031,6 +1031,7 @@ func (m *dbMeta) Fallocate(ctx Context, inode Ino, mode uint8, off uint64, size return err } if mode&(fallocZeroRange|fallocPunchHole) != 0 && off < old { + off, size := off, size if off+size > old { size = old - off } @@ -2043,6 +2044,7 @@ func (m *dbMeta) CopyFileRange(ctx Context, fin Ino, offIn uint64, fout Ino, off *copied = 0 return nil } + size := size if offIn+size > nin.Length { size = nin.Length - offIn } diff --git a/pkg/meta/tkv.go b/pkg/meta/tkv.go index ca7bd01f5236..727cf1311f53 100644 --- a/pkg/meta/tkv.go +++ b/pkg/meta/tkv.go @@ -929,6 +929,7 @@ func (m *kvMeta) Fallocate(ctx Context, inode Ino, mode uint8, off uint64, size t.Ctimensec = uint32(now.Nanosecond()) tx.set(m.inodeKey(inode), m.marshal(&t)) if mode&(fallocZeroRange|fallocPunchHole) != 0 && off < old { + off, size := off, size if off+size > old { size = old - off } @@ -1727,6 +1728,7 @@ func (m *kvMeta) CopyFileRange(ctx Context, fin Ino, offIn uint64, fout Ino, off *copied = 0 return nil } + size := size if offIn+size > sattr.Length { size = sattr.Length - offIn }