-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Fix potential overflow #120357
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
base: main
Are you sure you want to change the base?
Fix potential overflow #120357
Conversation
Tagging subscribers to this area: @dotnet/ncl, @bartonjs, @vcsjones |
I assume you've meant |
Yes, sorry, fixed it |
short MinValue is -32768. That does not make much sense to me either. I could see the arguments that the length should be positive. |
The change was originally intended to only make the overflow impossible. But enforcing the positive length is more logical, I will change it. |
private static unsafe void SetField(ref MessageField field, int length, int offset) | ||
{ | ||
if (length > short.MaxValue) | ||
if (length > short.MaxValue || length < 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (length > short.MaxValue || length < 0) | |
if (length is < 0 or > short.MaxValue) |
As I understand, the length argument cannot be negative in practice, it is a cosmetic check.
Found by Linux Verification Center (linuxtesting.org) with SVACE.