aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/dirty_page_interval.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2020-08-16 23:47:34 -0700
committerChris Lu <chris.lu@gmail.com>2020-08-16 23:47:34 -0700
commit2ac27616bcc9f37adb22ccd00662584724d47a6d (patch)
treeed7292905de1bbcd9465855deafd8e7f5c4e4523 /weed/filesys/dirty_page_interval.go
parent48ed7f8a328ecaa40a21cac0a72c3711ca196a19 (diff)
downloadseaweedfs-2ac27616bcc9f37adb22ccd00662584724d47a6d.tar.xz
seaweedfs-2ac27616bcc9f37adb22ccd00662584724d47a6d.zip
fix possible out of range bytes
avoid buff out of range resp.Data = buff[:totalRead]
Diffstat (limited to 'weed/filesys/dirty_page_interval.go')
-rw-r--r--weed/filesys/dirty_page_interval.go15
1 files changed, 2 insertions, 13 deletions
diff --git a/weed/filesys/dirty_page_interval.go b/weed/filesys/dirty_page_interval.go
index ec94c6df1..10b74bb68 100644
--- a/weed/filesys/dirty_page_interval.go
+++ b/weed/filesys/dirty_page_interval.go
@@ -3,7 +3,6 @@ package filesys
import (
"bytes"
"io"
- "math"
)
type IntervalNode struct {
@@ -186,25 +185,15 @@ func (c *ContinuousIntervals) removeList(target *IntervalLinkedList) {
}
-func (c *ContinuousIntervals) ReadData(data []byte, startOffset int64) (offset int64, size int) {
- var minOffset int64 = math.MaxInt64
- var maxStop int64
+func (c *ContinuousIntervals) ReadData(data []byte, startOffset int64) (maxStop int64) {
for _, list := range c.lists {
start := max(startOffset, list.Offset())
stop := min(startOffset+int64(len(data)), list.Offset()+list.Size())
- if start <= stop {
+ if start < stop {
list.ReadData(data[start-startOffset:], start, stop)
- minOffset = min(minOffset, start)
maxStop = max(maxStop, stop)
}
}
-
- if minOffset == math.MaxInt64 {
- return 0, 0
- }
-
- offset = minOffset
- size = int(maxStop - offset)
return
}