Skip to content
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

Proper use of Stream.Read(buffer, offset, count) in the TemplateEngine.Core #3420

Merged
merged 4 commits into from
Jul 13, 2021

Conversation

vlada-shubina
Copy link
Member

@vlada-shubina vlada-shubina commented Jul 9, 2021

Problem

fixes #3325
The cause of the issue is: dotnet/runtime#53502, dotnet/docs#24649.

Solution

Affected code:

  • ProcessorState - reading from stream in a loop until buffer is filled; added unit and integration tests
  • CombinedStream - reading from stream in a loop until count is reached; added unit tests
  • Include - reading from stream in a loop until count is reached
  • in cases when MemoryStream is used replaced with using MemoryStream.ToArray() instead

Include is not covered with tests: extracted to #3438

Checks:

  • Added unit tests
  • Added #nullable enable to all the modified files ? - partially

@vlada-shubina vlada-shubina requested a review from a team as a code owner July 9, 2021 09:12
@vlada-shubina vlada-shubina changed the title Stream read fix Proper use of Stream.Read(buffer, offset, count) in the TemplateEngine.Core Jul 9, 2021
src/Microsoft.TemplateEngine.Core/Operations/Include.cs Outdated Show resolved Hide resolved
src/Microsoft.TemplateEngine.Core/Operations/Include.cs Outdated Show resolved Hide resolved
src/Microsoft.TemplateEngine.Core/Operations/Include.cs Outdated Show resolved Hide resolved
src/Microsoft.TemplateEngine.Core/Util/ProcessorState.cs Outdated Show resolved Hide resolved
src/Microsoft.TemplateEngine.Core/Util/ProcessorState.cs Outdated Show resolved Hide resolved
int totalBytesRead = 0;
if (!_isStream1Depleted)
{
while (totalBytesRead < count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest we do partial reads here and leave handling this to the caller, just like any other streams.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's delay it when tests on InlineMarkupConditional (where CombinedStream is used) are written. I prefer to have keep implementation as is for now.

@vlada-shubina vlada-shubina merged commit b45b3f6 into dotnet:main Jul 13, 2021
@vlada-shubina vlada-shubina deleted the stream-read-fix branch July 13, 2021 10:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

'dotnet new android' produces invalid images
2 participants