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 panic: runtime error: slice bounds out of range #5264

Merged
merged 1 commit into from
Jan 4, 2016
Merged

Conversation

jwilder
Copy link
Contributor

@jwilder jwilder commented Jan 4, 2016

The block count was an uint16 when incrementing the index location
which was an int32. This caused the value the uint16 value to overflow
before the index location was incremented causing the wrong location
to be read on the next iteration of the loop. This triggers the slice
out of range errors.

Added a test that recreates the panic seen in #5257 and possibly #5202 which
is older code.

Fixes #5257

The block count was an uint16 when incrementing the index location
which was an int32.  This caused the value the uint16 value to overflow
before the index location was incremented causing the wrong location
to be read on the next iteration of the loop.  This triggers the slice
out of range errors.

Added a test that recreates the panic seen in #5257 and possibly #5202 which
is older code.

Fixes #5257
@@ -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]))
Copy link
Contributor

Choose a reason for hiding this comment

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

I must be dense, but I don't see how this affects anything. Where exactly does a 16-bit wide count affect anything?

Copy link
Contributor

Choose a reason for hiding this comment

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

I.e. by its nature btou16 returns a 16-bit type. And since count is never incremented, how it could it overflow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You can't see where it is incremented in the diff. It happens on here: https://github.com/influxdb/influxdb/pull/5264/files#diff-2226d419783ec10497f3bab10d1c4300R619

See this snippet for essentially what is happening: https://play.golang.org/p/zMYh_UOw4h

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, I see it now. 28 is shoved into 16 bits too.

The change is a little obscure. Would it be better to move the casting to nearer where it matters? That would probably make it clearer to the next guy.

I.e.

i += int32(count) - 1 * int32(indexEntrySize))

You get the idea -- deal with the overflow at the point where it matters.

@otoolep
Copy link
Contributor

otoolep commented Jan 4, 2016

+1

@otoolep
Copy link
Contributor

otoolep commented Jan 4, 2016

I have some feedback but I understand the fix now.

@toddboom
Copy link
Contributor

toddboom commented Jan 4, 2016

@jwilder installed your branch on those nodes and confirmed that it fixed the issue. nice job! 👍

jwilder added a commit that referenced this pull request Jan 4, 2016
Fix panic: runtime error: slice bounds out of range
@jwilder jwilder merged commit 3bd323d into master Jan 4, 2016
@jwilder jwilder deleted the jw-5257 branch January 4, 2016 20:51
@ivanscattergood
Copy link

@jwilder I was looking at the Changelog and I cannot see this issue (#5264):

https://github.com/influxdata/influxdb/blob/master/CHANGELOG.md

I am keen to test to see if this fixes #5202 & #5283

@jwilder
Copy link
Contributor Author

jwilder commented Jan 7, 2016

@ivanscattergood I updated the change log. It should be in the current nightlies. If you could test it out for those two issues, that would be great.

@jwilder jwilder added this to the 0.10.0 milestone Feb 1, 2016
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.

4 participants