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

findNextPositivePowerOfTwo out of bounds #5603

Closed
wants to merge 1 commit into from

Conversation

Scottmitch
Copy link
Member

Motivation:
Some usages of findNextPositivePowerOfTwo assume that bounds checking is taken care of by this method. However bounds checking is not taken care of by findNextPositivePowerOfTwo and instead assert statements are used to imply the caller has checked the bounds. This can lead to unexpected non power of 2 return values if the caller is not careful and thus invalidate any logic which depends upon a power of 2.

Modifications:

  • Add a safeFindNextPositivePowerOfTwo method which will do runtime bounds checks and always return a power of 2

Result:
Fixes #5601

Motivation:
Some usages of findNextPositivePowerOfTwo assume that bounds checking is taken care of by this method. However bounds checking is not taken care of by findNextPositivePowerOfTwo and instead assert statements are used to imply the caller has checked the bounds. This can lead to unexpected non power of 2 return values if the caller is not careful and thus invalidate any logic which depends upon a power of 2.

Modifications:
- Add a safeFindNextPositivePowerOfTwo method which will do runtime bounds checks and always return a power of 2

Result:
Fixes netty#5601
@Scottmitch Scottmitch added this to the 4.0.41.Final milestone Jul 29, 2016
@Scottmitch Scottmitch self-assigned this Jul 29, 2016
@Scottmitch
Copy link
Member Author

@normanmaurer - FYI

@normanmaurer
Copy link
Member

@Scottmitch LGTM... ship it

@Scottmitch
Copy link
Member Author

4.0 (4fb7a52) 4.1 (82b22d6)

@Scottmitch Scottmitch closed this Aug 2, 2016
@Scottmitch Scottmitch deleted the next_pow_2_safe branch August 2, 2016 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants