-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
MemoryStream.ValidatePosition throws when Position == length #3536
Comments
Hello tombarry25, thank you for opening an issue with us! I have automatically added a "needs triage" label to help get things started. Our team will analyze and investigate the issue, and escalate it to the relevant team if possible. Other community members may also look into the issue and provide feedback 🙌 |
@tombarry25 Can you please provide detailed information and expected behavior? Screenshots/gifs are highly recommended. Thanks! |
Hello Kyaa,
Not sure what else I can provide. The issue I entered has code to reproduce the error and even where I think the problem might be.
So, unlike other streams, you are unable to set the Position of the Microsoft.Toolkit.HighPerformance.Streams.MemoryStream equal to its Length. You also are unable to seek to the end of the stream either. Both throw an out of range exception.
The snippet of code I provided demonstrates reading to the end of the stream so that stream.Position == stream.Length. But if you then try to set the stream’s position to the value it already has it throws. I believe it throws because the ValidatePosition(long position, int length) compares position to length with a >= when it should be strictly >. In other words, setting Postion equal to Length for a stream should not throw.
Hope this helps.
|
@Sergio0694 this one's for you! 🙂 |
Hey @tombarry25, thanks for the detailed issue and repro, and for spotting the bug! 😄 You were absolutely correct, the stream shouldn't throw an exception when seeking to the end. |
Sounds good. Thanks for the quick turnaround.
|
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> ## Fixes #3536 <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> - Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Seeking to the end of a `Stream` from a `Memory<T>` or other types in the `HighPerformance` package throws an exception. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> Seeking to the end of the stream is now allowed. This is consistent to other `Stream` types in the BCL. ## PR Checklist Please check if your PR fulfills the following requirements: - [X] Tested code with current [supported SDKs](../readme.md#supported) - [ ] ~~Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->~~ - [ ] ~~Sample in sample app has been added / updated (for bug fixes / features)~~ - [ ] ~~Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https:/windows-toolkit/WindowsCommunityToolkit-design-assets)~~ - [X] Tests for the changes have been added (for bug fixes / features) (if applicable) - [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> ## Fixes CommunityToolkit/WindowsCommunityToolkit#3536 <!-- Add the relevant issue number after the "#" mentioned above (for ex: Fixes #1234) which will automatically close the issue once the PR is merged. --> <!-- Add a brief overview here of the feature/bug & fix. --> ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> - Bugfix <!-- - Feature --> <!-- - Code style update (formatting) --> <!-- - Refactoring (no functional changes, no api changes) --> <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Seeking to the end of a `Stream` from a `Memory<T>` or other types in the `HighPerformance` package throws an exception. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> Seeking to the end of the stream is now allowed. This is consistent to other `Stream` types in the BCL. ## PR Checklist Please check if your PR fulfills the following requirements: - [X] Tested code with current [supported SDKs](../readme.md#supported) - [ ] ~~Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link -->~~ - [ ] ~~Sample in sample app has been added / updated (for bug fixes / features)~~ - [ ] ~~Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https:/windows-toolkit/WindowsCommunityToolkit-design-assets)~~ - [X] Tests for the changes have been added (for bug fixes / features) (if applicable) - [X] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [X] Contains **NO** breaking changes
If you read to the end of the MemoryStream, Position == length. If you then try to
call mstrm.Postion = mstrm.Position, it throws an ArgOutOfRangeException
In MemoryStream.cs, should probably be '>' rather than '>=' to be consistent with the behavior of other streams
NuGet Package(s): microsoft.toolkit.highperformance
Package Version(s): v6.1.1
Windows 10 Build Number:
App min and target version:
Device form factor:
Visual Studio
The text was updated successfully, but these errors were encountered: