From 367e7638d78e5f5bc373a6ae668cc2390308bba2 Mon Sep 17 00:00:00 2001 From: Guang Jiong Lou <7991675+27149chen@users.noreply.github.com> Date: Mon, 16 Sep 2024 23:45:50 +0800 Subject: [PATCH] fix invalid file read (#6024) --- weed/filer/filechunk_group.go | 4 ++++ weed/mount/filehandle_read.go | 5 ++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/weed/filer/filechunk_group.go b/weed/filer/filechunk_group.go index dbeb54ce8..ebda62845 100644 --- a/weed/filer/filechunk_group.go +++ b/weed/filer/filechunk_group.go @@ -1,6 +1,7 @@ package filer import ( + "io" "sync" "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" @@ -44,6 +45,9 @@ func (group *ChunkGroup) AddChunk(chunk *filer_pb.FileChunk) error { } func (group *ChunkGroup) ReadDataAt(fileSize int64, buff []byte, offset int64) (n int, tsNs int64, err error) { + if offset >= fileSize { + return 0, 0, io.EOF + } group.sectionsLock.RLock() defer group.sectionsLock.RUnlock() diff --git a/weed/mount/filehandle_read.go b/weed/mount/filehandle_read.go index 3c315b1c4..faf99952f 100644 --- a/weed/mount/filehandle_read.go +++ b/weed/mount/filehandle_read.go @@ -47,6 +47,9 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, e if fileSize == 0 { glog.V(1).Infof("empty fh %v", fileFullPath) return 0, 0, io.EOF + } else if offset >= fileSize { + glog.V(1).Infof("invalid read, fileSize %d, offset %d for %s", fileSize, offset, fileFullPath) + return 0, 0, io.EOF } if offset < int64(len(entry.Content)) { @@ -66,7 +69,7 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, e return int64(totalRead), ts, err } -func (fh *FileHandle) downloadRemoteEntry(entry *LockedEntry) (error) { +func (fh *FileHandle) downloadRemoteEntry(entry *LockedEntry) error { fileFullPath := fh.FullPath() dir, _ := fileFullPath.DirAndName()