-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Creation of arrays with negative lengths? #110949
Comments
How do you even end up having 2 billion work items in the first place? Are you just pushing more and more items in an endless loop or something? Expanding an array more and more won't help you as it is a clear indication of a bug in your code |
Trying to create array of negative length will throw an exception. It's a safe behavior for handling exceptional cases. |
Tagging subscribers to this area: @mangod9 |
Security-wise, it's still important to get exceptionally large content correctly rejected, instead of causing security issues like buffer overrun. |
@jerviscui is the question basically "how can byte[] arr = new byte[1_100_000_000];
Console.WriteLine(arr.Length << 1); |
This issue has been marked |
If you start with a very large signed integer, which has the second-most-significant-bit set, the left-shift will shift that bit into the most-significant position. This then represents a negative number, because the most-significant bit is set. This is expected behavior. I don't think it's an issue/bug in .NET. |
runtime/src/libraries/System.Private.CoreLib/src/System/Threading/ThreadPoolWorkQueue.cs
Line 138 in 2b60d82
I have a problem where a continuous left shift goes negative, and the code throws an exception.
Am I missing something?
The text was updated successfully, but these errors were encountered: