Skip to content

Commit 6d975f9

Browse files
github-actions[bot]Kuinoxsafern
authored
[release/5.0] Fixes #62167. WriteAsync may truncate data if called after .Advance(int) (#62350)
* Fixes #62167. WriteAsync was bugged when writing multiple segments if called after an .Advance(int) * Add packaging changes Co-authored-by: Kuinox <[email protected]> Co-authored-by: Santiago Fernandez Madero <[email protected]>
1 parent 3b960e4 commit 6d975f9

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

src/libraries/System.IO.Pipelines/Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<Import Project="..\Directory.Build.props" />
33
<PropertyGroup>
44
<StrongNameKeyId>Open</StrongNameKeyId>
5-
<ServicingVersion>1</ServicingVersion>
5+
<ServicingVersion>2</ServicingVersion>
66
<!-- This should be pinned to 5.0.0.1 for non-netfx assets as it is part of aspnetcore ref pack.-->
77
<AssemblyVersion>5.0.0.1</AssemblyVersion>
88
</PropertyGroup>

src/libraries/System.IO.Pipelines/src/System/IO/Pipelines/Pipe.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ private void WriteMultiSegment(ReadOnlySpan<byte> source)
10111011
}
10121012

10131013
// We filled the segment
1014-
_writingHead.End += writable;
1014+
_writingHead.End += _writingHeadBytesBuffered;
10151015
_writingHeadBytesBuffered = 0;
10161016

10171017
// This is optimized to use pooled memory. That's why we pass 0 instead of

src/libraries/System.IO.Pipelines/tests/PipeLengthTests.cs

+14
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,19 @@ public async Task NullExaminedAndConsumedNoops()
277277
ReadResult result = await _pipe.Reader.ReadAsync();
278278
_pipe.Reader.AdvanceTo(default, default);
279279
}
280+
281+
[Fact]
282+
public async Task AdvanceFollowedByWriteAsyncTest()
283+
{
284+
Memory<byte> buffer = new byte[26];
285+
Pipe pipe = new(new PipeOptions(minimumSegmentSize: 1));
286+
287+
var mem = pipe.Writer.GetMemory(14)[..14];
288+
buffer[..14].CopyTo(mem);
289+
pipe.Writer.Advance(14);
290+
await pipe.Writer.WriteAsync(buffer[14..]);
291+
ReadResult res = await pipe.Reader.ReadAsync();
292+
Assert.Equal(res.Buffer.Length, buffer.Length);
293+
}
280294
}
281295
}

src/libraries/libraries-packages.proj

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
<ProjectReference Include="$(PkgDir)*\*.proj" Exclude="$(PkgDir)test\*" Condition="'$(BuildAllOOBPackages)' == 'true'" />
1919
<ProjectReference Include="$(MSBuildThisFileDirectory)*\pkg\**\*.pkgproj" Condition="('$(BuildAllConfigurations)' == 'true' or '$(DotNetBuildFromSource)' == 'true') And '$(BuildAllOOBPackages)' == 'true'" />
2020
<!-- If setting BuildAllOOBPackages to false, add bellow the individual OOB packages you want to continue to build -->
21+
<ProjectReference Include="$(MSBuildThisFileDirectory)System.IO.Pipelines\pkg\System.IO.Pipelines.pkgproj" Condition="('$(BuildAllConfigurations)' == 'true' or '$(DotNetBuildFromSource)' == 'true') And '$(BuildAllOOBPackages)' == 'true'" />
2122
<!-- This is merge marker 1 to help automerge -->
2223
<!-- This is merge marker 2 to help automerge -->
2324
<!-- This is merge marker 3 to help automerge -->

0 commit comments

Comments
 (0)