Skip to content

[release/5.0] Fixes #62167. WriteAsync may truncate data if called after .Advance(int) #62350

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

Merged
merged 2 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libraries/System.IO.Pipelines/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Import Project="..\Directory.Build.props" />
<PropertyGroup>
<StrongNameKeyId>Open</StrongNameKeyId>
<ServicingVersion>1</ServicingVersion>
<ServicingVersion>2</ServicingVersion>
<!-- This should be pinned to 5.0.0.1 for non-netfx assets as it is part of aspnetcore ref pack.-->
<AssemblyVersion>5.0.0.1</AssemblyVersion>
</PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1011,7 +1011,7 @@ private void WriteMultiSegment(ReadOnlySpan<byte> source)
}

// We filled the segment
_writingHead.End += writable;
_writingHead.End += _writingHeadBytesBuffered;
_writingHeadBytesBuffered = 0;

// This is optimized to use pooled memory. That's why we pass 0 instead of
Expand Down
14 changes: 14 additions & 0 deletions src/libraries/System.IO.Pipelines/tests/PipeLengthTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,5 +277,19 @@ public async Task NullExaminedAndConsumedNoops()
ReadResult result = await _pipe.Reader.ReadAsync();
_pipe.Reader.AdvanceTo(default, default);
}

[Fact]
public async Task AdvanceFollowedByWriteAsyncTest()
{
Memory<byte> buffer = new byte[26];
Pipe pipe = new(new PipeOptions(minimumSegmentSize: 1));

var mem = pipe.Writer.GetMemory(14)[..14];
buffer[..14].CopyTo(mem);
pipe.Writer.Advance(14);
await pipe.Writer.WriteAsync(buffer[14..]);
ReadResult res = await pipe.Reader.ReadAsync();
Assert.Equal(res.Buffer.Length, buffer.Length);
}
}
}
1 change: 1 addition & 0 deletions src/libraries/libraries-packages.proj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ProjectReference Include="$(PkgDir)*\*.proj" Exclude="$(PkgDir)test\*" Condition="'$(BuildAllOOBPackages)' == 'true'" />
<ProjectReference Include="$(MSBuildThisFileDirectory)*\pkg\**\*.pkgproj" Condition="('$(BuildAllConfigurations)' == 'true' or '$(DotNetBuildFromSource)' == 'true') And '$(BuildAllOOBPackages)' == 'true'" />
<!-- If setting BuildAllOOBPackages to false, add bellow the individual OOB packages you want to continue to build -->
<ProjectReference Include="$(MSBuildThisFileDirectory)System.IO.Pipelines\pkg\System.IO.Pipelines.pkgproj" Condition="('$(BuildAllConfigurations)' == 'true' or '$(DotNetBuildFromSource)' == 'true') And '$(BuildAllOOBPackages)' == 'true'" />
<!-- This is merge marker 1 to help automerge -->
<!-- This is merge marker 2 to help automerge -->
<!-- This is merge marker 3 to help automerge -->
Expand Down