-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
CryptoStream.Read(Byte[], Int32, Int32) read the wrong data #64144
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
Tagging subscribers to this area: @dotnet/area-system-security, @vcsjones, @krwq Issue DetailsWhen I use class System.Security.Cryptography.CryptoStream to read my data. It came up with wrong data. https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.cryptostream.read Test C# .net 6.0 with Visual Studio 2022 As it appears in complex projects. I simplified the process.
When this function is called, 100 bytes should be returned. But it only returned 99 bytes. Stream's length exceeds 10000. I checked the C# source code and found the following code snippet.
The key snippets are below.
Why does it return directly after comparing the minimum value of two numbers? It doesn't count all the data based on the count parameter. If it is because it reaches the end. But when I call the function again, it still can return values.
|
This is a known breaking change that was introduced in .NET 6. See Partial and zero-byte reads in DeflateStream, GZipStream, and CryptoStream.
That is not the contract for
In short, you need to call |
Thank you. I can see this code in your url:
Do you think it can be provided as an new API function/method name by .NET? Because some users may not care much about the underlying logic, they just want to read enough data and be less prone to errors. Error-prone when duplicating these computational steps. |
Possibly! If you feel that a new API would be useful for developers, feel free to write an API Proposal with your suggestion. From there, the API review process will be followed. If you want help or prefer that I write the proposal, let me know. |
Thank you. My english is not very good. I use Google Translate to convert languages. If you can fill a Proposal. It's the best for me. |
|
When I use class System.Security.Cryptography.CryptoStream to read my data. It came up with wrong data.
https://docs.microsoft.com/zh-cn/dotnet/api/system.security.cryptography.cryptostream.read
Test C# .net 6.0 with Visual Studio 2022
As it appears in complex projects. I simplified the process.
When this function is called, 100 bytes should be returned. But it only returned 99 bytes. Stream's length exceeds 10000.
I checked the C# source code and found the following code snippet.
The key snippets are below.
Why does it return directly after comparing the minimum value of two numbers?
It doesn't count all the data based on the count parameter.
If it is because it reaches the end. But when I call the function again, it still can return values.
I can get the remaining 1 byte by calling it at the second time.
The text was updated successfully, but these errors were encountered: