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 TSM UnmarshalBinary panic #6170

Merged
merged 3 commits into from
Mar 31, 2016
Merged

Fix TSM UnmarshalBinary panic #6170

merged 3 commits into from
Mar 31, 2016

Conversation

jwilder
Copy link
Contributor

@jwilder jwilder commented Mar 31, 2016

Required for all non-trivial PRs
  • Rebased/mergable
  • Tests pass
  • CHANGELOG.md updated
  • Sign CLA (if not already signed)

If writing points ended up creating a key (measurement + tag sets) that was larger than 65535 bytes, it could overflow the length bytes in the the TSM index causing a panic when opening the file:

panic: runtime error: slice bounds out of range

goroutine 71 [running]:
github.com/influxdb/influxdb/tsdb/engine/tsm1.(*indirectIndex).UnmarshalBinary(0xc222850f00, 0x7f715
abea3c9, 0x7efa2a, 0x7efa32, 0x0, 0x0)
        /tmp/tmp.n7AHL1nb9U/src/github.com/influxdb/influxdb/tsdb/engine/tsm1/reader.go:639 +0x45f

I was able to reproduce this panic in a test by writing a key of 100k bytes.

This PR checks for that condition in the TSM writer so that an error is returned if a large key is written. It also adds validation to models.Point to prevent creating a point that would exceed the max key length.

May fix #6121 #6022 #6054 #5202

jwilder added 3 commits March 30, 2016 23:44
Writing a key that exceeds the max key length could cause a panic
when reading a tsm file because the 2 bytes used for the key length
would not be enough to represent the actual key length.

The writer will now return an error if when trying to write a key
that is too large.
@jwilder jwilder added this to the 0.12.0 milestone Mar 31, 2016
@e-dard
Copy link
Contributor

e-dard commented Mar 31, 2016

LGTM.

@jwilder jwilder merged commit e7cce69 into master Mar 31, 2016
@jwilder jwilder deleted the jw-tsm-panic branch March 31, 2016 14:44
@jwilder jwilder modified the milestones: 0.11.1, 0.12.0 Mar 31, 2016
t.Fatalf("unexpected error created writer: %v", err)
}

var key string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about doing this instead?

var key = make([]byte,100000)
for i := range key { key[i] = 'a' }

And then just pass string(key) to w.Write(). I know it's "just a test", but I don't like that we'd be creating over 100000 strings here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Influxdb 0.11 Slice index out of bounds
3 participants