Skip to content

Commit

Permalink
Merge pull request #5264 from influxdb/jw-5257
Browse files Browse the repository at this point in the history
Fix panic: runtime error: slice bounds out of range
  • Loading branch information
jwilder committed Jan 4, 2016
2 parents a2df2ff + 7794b9c commit 3bd323d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tsdb/engine/tsm1/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,7 @@ func (d *indirectIndex) UnmarshalBinary(b []byte) error {
i++

// 2 byte count of index entries
count := btou16(b[i : i+indexCountSize])
count := int32(btou16(b[i : i+indexCountSize]))
i += indexCountSize

// Find the min time for the block
Expand Down
38 changes: 38 additions & 0 deletions tsdb/engine/tsm1/reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,6 +739,44 @@ func TestBlockIterator_Sorted(t *testing.T) {
}
}

func TestIndirectIndex_UnmarshalBinary_BlockCountOverflow(t *testing.T) {
dir := MustTempDir()
defer os.RemoveAll(dir)
f := MustTempFile(dir)
defer f.Close()

w, err := tsm1.NewTSMWriter(f)
if err != nil {
t.Fatalf("unexpected error creating writer: %v", err)
}

for i := 0; i < 3280; i++ {
w.Write("cpu", []tsm1.Value{tsm1.NewValue(time.Unix(int64(i), 0), float64(i))})
}

if err := w.WriteIndex(); err != nil {
t.Fatalf("unexpected error closing: %v", err)
}

if err := w.Close(); err != nil {
t.Fatalf("unexpected error closing: %v", err)
}

f, err = os.Open(f.Name())
if err != nil {
t.Fatalf("unexpected error open file: %v", err)
}

r, err := tsm1.NewTSMReaderWithOptions(
tsm1.TSMReaderOptions{
MMAPFile: f,
})
if err != nil {
t.Fatalf("unexpected error created reader: %v", err)
}
defer r.Close()
}

func BenchmarkIndirectIndex_UnmarshalBinary(b *testing.B) {
index := tsm1.NewDirectIndex()
for i := 0; i < 100000; i++ {
Expand Down

0 comments on commit 3bd323d

Please sign in to comment.