Fix IOStreamStreamReader to account for alignment padding #1047
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.
When reading a non-seekable stream, the
IOStreamStreamReader
class can be put in a state where it attempts to read a count greater than length - offset of its internal buffer.simple repro
This happens because the constructor for the class pads the buffer size by
align
bytes so that it has room to round up the number of bytes read to an aligned value. The reading logic doesn't preserve the padding and uses therequestedSize + align
length for some of its logic which is how we get into this corner case. It is a rare occurrence, but this has been what is causing CI failures in CoreCLR (see: dotnet/coreclr#26241).I'm going to be testing this locally with EventPipe workloads (a main use case for this class).
CC - @tommcdon, @brianrob, @noahfalk, @sywhang