Skip to content

Commit

Permalink
Merge pull request #8970 from influxdata/jw-wal-panic
Browse files Browse the repository at this point in the history
Fix corrupted wal segment panic on 32 bit systems
  • Loading branch information
jwilder authored Oct 16, 2017
2 parents 5bf9191 + fb7135d commit bc360cc
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
- [#8900](https://github.com/influxdata/influxdb/issues/8900): Don't assume `which` is present in package post-install script.
- [#8908](https://github.com/influxdata/influxdb/issues/8908): Fix missing man pages in new packaging output
- [#8909](https://github.com/influxdata/influxdb/issues/8909): Fix use of `INFLUXD_OPTS` in service file
- [#8952](https://github.com/influxdata/influxdb/issues/8952): Fix WAL panic: runtime error: makeslice: cap out of range

## v1.3.4 [unreleased]

Expand Down
4 changes: 4 additions & 0 deletions tsdb/engine/tsm1/wal.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,10 @@ func (w *WriteWALEntry) UnmarshalBinary(b []byte) error {
nvals := int(binary.BigEndian.Uint32(b[i : i+4]))
i += 4

if nvals <= 0 || nvals > len(b) {
return ErrWALCorrupt
}

switch typ {
case float64EntryType:
if i+16*nvals > len(b) {
Expand Down
46 changes: 46 additions & 0 deletions tsdb/engine/tsm1/wal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,52 @@ func TestWALWriter_Corrupt(t *testing.T) {
}
}

// Reproduces a `panic: runtime error: makeslice: cap out of range` when run with
// GOARCH=386 go test -run TestWALSegmentReader_Corrupt -v ./tsdb/engine/tsm1/
func TestWALSegmentReader_Corrupt(t *testing.T) {
dir := MustTempDir()
defer os.RemoveAll(dir)
f := MustTempFile(dir)
w := tsm1.NewWALSegmentWriter(f)

p4 := tsm1.NewValue(1, "string")

values := map[string][]tsm1.Value{
"cpu,host=A#!~#string": []tsm1.Value{p4, p4},
}

entry := &tsm1.WriteWALEntry{
Values: values,
}

typ, b := mustMarshalEntry(entry)

// This causes the nvals field to overflow on 32 bit systems which produces a
// negative count and a panic when reading the segment.
b[25] = 255

if err := w.Write(typ, b); err != nil {
fatal(t, "write points", err)
}

if err := w.Flush(); err != nil {
fatal(t, "flush", err)
}

// Create the WAL segment reader.
if _, err := f.Seek(0, io.SeekStart); err != nil {
fatal(t, "seek", err)
}

r := tsm1.NewWALSegmentReader(f)
defer r.Close()

// Try to decode two entries.
for r.Next() {
r.Read()
}
}

func TestWriteWALSegment_UnmarshalBinary_WriteWALCorrupt(t *testing.T) {
p1 := tsm1.NewValue(1, 1.1)
p2 := tsm1.NewValue(1, int64(1))
Expand Down

0 comments on commit bc360cc

Please sign in to comment.