Issue #60416 - Correction of BufferedReadStream 's Position #60529
+39
−3
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.
Correction of Microsoft.AspNetCore.WebUtilities.BufferedReadStream Position property
The implementation of Position's property setter for Microsoft.AspNetCore.WebUtilities.BufferedReadStream class was incorrect and changed accordingly with the proposed solution described in the issue #60416 .
Description
By trying to use Microsoft.AspNetCore.WebUtilities.MultipartReader in a way that is directly using the section streams outside the initial reading loop (made through ReadNextSectionAsync), I've come to at least one case (when dealing with more than two section streams) where the conclusion is that the Position property of BufferedReadStream has an incorrect implementation when trying to position inside the internal buffer.
The solution was to advance in the internal buffer not with the offset between old position and new position (i.e. backward innerOffset), but until that offset / distance, so in the end the new Position will reflect the desired input value when getting the property.
Fixes #60416