mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Signed-off-by: Derek Collison <derek@nats.io>
This commit is contained in:
@@ -2289,6 +2289,12 @@ func (mb *msgBlock) readIndexInfo() error {
|
||||
mb.last.ts = readTimeStamp()
|
||||
dmapLen := readCount()
|
||||
|
||||
// Check if this is a short write index file.
|
||||
if bi < 0 || bi+checksumSize > len(buf) {
|
||||
defer os.Remove(mb.ifn)
|
||||
return fmt.Errorf("short index file")
|
||||
}
|
||||
|
||||
// Checksum
|
||||
copy(mb.lchk[0:], buf[bi:bi+checksumSize])
|
||||
bi += checksumSize
|
||||
|
||||
@@ -17,6 +17,7 @@ import (
|
||||
"archive/tar"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@@ -28,6 +29,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
@@ -2410,3 +2412,16 @@ func TestFileStoreConsumerPerf(t *testing.T) {
|
||||
oc.syncStateFile()
|
||||
fmt.Printf("time to sync is %v\n", time.Since(start))
|
||||
}
|
||||
|
||||
func TestFileStoreStreamIndexBug(t *testing.T) {
|
||||
// https://github.com/nats-io/jetstream/issues/406
|
||||
badIdxBytes, _ := base64.StdEncoding.DecodeString("FgGBkw7D/f8/772iDPDIgbU=")
|
||||
dir, _ := ioutil.TempDir("", "js-bad-idx-")
|
||||
defer os.RemoveAll(dir)
|
||||
fn := path.Join(dir, "1.idx")
|
||||
ioutil.WriteFile(fn, badIdxBytes, 0644)
|
||||
mb := &msgBlock{index: 1, ifn: fn}
|
||||
if err := mb.readIndexInfo(); err == nil || !strings.Contains(err.Error(), "short index") {
|
||||
t.Fatalf("Expected error during readIndexInfo(): %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user