Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix corrupted wal segment panic on 32 bit systems #8970

Merged
merged 1 commit into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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