From f06ca04451037bf4b250da55d408d06fc691c760 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 27 Mar 2020 04:35:31 -0700 Subject: [PATCH] avoid overflow --- weed/filer2/filechunks.go | 7 +++++++ weed/filer2/stream.go | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/weed/filer2/filechunks.go b/weed/filer2/filechunks.go index fe7841fa7..4c972e14f 100644 --- a/weed/filer2/filechunks.go +++ b/weed/filer2/filechunks.go @@ -3,6 +3,7 @@ package filer2 import ( "fmt" "hash/fnv" + "math" "sort" "sync" @@ -86,6 +87,12 @@ func ViewFromChunks(chunks []*filer_pb.FileChunk, offset int64, size int64) (vie func ViewFromVisibleIntervals(visibles []VisibleInterval, offset int64, size int64) (views []*ChunkView) { stop := offset + size + if size == math.MaxInt64 { + stop = math.MaxInt64 + } + if stop < offset { + stop = math.MaxInt64 + } for _, chunk := range visibles { diff --git a/weed/filer2/stream.go b/weed/filer2/stream.go index d71ef71f6..6dbc1ce72 100644 --- a/weed/filer2/stream.go +++ b/weed/filer2/stream.go @@ -61,7 +61,7 @@ var _ = io.ReadSeeker(&ChunkStreamReader{}) func NewChunkStreamReaderFromFiler(masterClient *wdclient.MasterClient, chunks []*filer_pb.FileChunk) *ChunkStreamReader { - chunkViews := ViewFromChunks(chunks, 0, math.MaxInt64) + chunkViews := ViewFromChunks(chunks, 0, math.MaxInt32) return &ChunkStreamReader{ chunkViews: chunkViews,