This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
[release/3.1] Fix ReadOnlySequence created out of sliced Memory owned by MemoryManager #43102
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Port dotnet/runtime#57479 to release/3.1
The following description is a copy of the port to 5.0 description (dotnet/runtime#57562)
Customer Impact
Customers who create
ReadOnlySequence<T>
out of slicedMemory
owned by anyMemoryManager
are seeing invalid end position and length. This issue was reported by a customer and the fix was provided by them as well.Depending on the input (how many elements of the original
Memory
were sliced) iteration overReadOnlySequence<T>
can result in returning incomplete data or throwingArgumentOutOfRangeException
. These conditions can lead to data loss or data corruption that would be difficult to diagnose in a production application.Testing
Failing test has been added in this PR.
Risk
Low, as the change is very simple and obvious when you look at
ReadOnlySequence<T>
ctor that acceptsReadOnlyMemory<T>
:corefx/src/System.Memory/src/System/Buffers/ReadOnlySequence.cs
Line 165 in 646a219
corefx/src/System.Memory/src/System/Buffers/ReadOnlySequence.cs
Line 175 in 646a219
Regression
This is not a regression.