mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-07-15 09:57:26 +08:00
fix invalid file read (#6024)
This commit is contained in:
parent
0da9e40abb
commit
367e7638d7
@ -1,6 +1,7 @@
|
|||||||
package filer
|
package filer
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/seaweedfs/seaweedfs/weed/pb/filer_pb"
|
"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) {
|
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()
|
group.sectionsLock.RLock()
|
||||||
defer group.sectionsLock.RUnlock()
|
defer group.sectionsLock.RUnlock()
|
||||||
|
@ -47,6 +47,9 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, e
|
|||||||
if fileSize == 0 {
|
if fileSize == 0 {
|
||||||
glog.V(1).Infof("empty fh %v", fileFullPath)
|
glog.V(1).Infof("empty fh %v", fileFullPath)
|
||||||
return 0, 0, io.EOF
|
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)) {
|
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
|
return int64(totalRead), ts, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fh *FileHandle) downloadRemoteEntry(entry *LockedEntry) (error) {
|
func (fh *FileHandle) downloadRemoteEntry(entry *LockedEntry) error {
|
||||||
|
|
||||||
fileFullPath := fh.FullPath()
|
fileFullPath := fh.FullPath()
|
||||||
dir, _ := fileFullPath.DirAndName()
|
dir, _ := fileFullPath.DirAndName()
|
||||||
|
Loading…
Reference in New Issue
Block a user