Skip to content

Move NoInt32OverflowInTheBufferingLogic to OuterLoop #60606

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 1 commit into from
Oct 19, 2021
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
16 changes: 3 additions & 13 deletions src/libraries/System.IO.FileSystem/tests/FileStream/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void NegativeReadRootThrows()
}

[Fact]
[OuterLoop]
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
public void NoInt32OverflowInTheBufferingLogic()
{
Expand All @@ -30,10 +31,10 @@ public void NoInt32OverflowInTheBufferingLogic()
using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
stream.Seek(position1, SeekOrigin.Begin);
stream.Write(data1, 0, data1.Length);
stream.Write(data1);

stream.Seek(position2, SeekOrigin.Begin);
stream.Write(data2, 0, data2.Length);
stream.Write(data2);
}

using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
Expand All @@ -46,17 +47,6 @@ public void NoInt32OverflowInTheBufferingLogic()
Assert.Equal(buffer.Length, stream.Read(buffer));
Assert.Equal(data2, buffer);
}

using (var stream = new BufferedStream(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize: 0)))
{
stream.Seek(position1, SeekOrigin.Begin);
Assert.Equal(buffer.Length, stream.Read(buffer));
Assert.Equal(data1, buffer);

stream.Seek(position2, SeekOrigin.Begin);
Assert.Equal(buffer.Length, stream.Read(buffer));
Assert.Equal(data2, buffer);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,40 @@ public async Task CopyToTest_ReadBeforeCopy_CopiesAllData(bool copyAsynchronousl
Array.Copy(data, 1, expected, 0, expected.Length);
Assert.Equal(expected, dst.ToArray());
}

[Fact]
[OuterLoop]
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
public void NoInt32OverflowInTheBufferingLogic()
{
const long position1 = 10;
const long position2 = (1L << 32) + position1;

string filePath = Path.GetTempFileName();
byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
byte[] buffer = new byte[5];

using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
{
stream.Seek(position1, SeekOrigin.Begin);
stream.Write(data1);

stream.Seek(position2, SeekOrigin.Begin);
stream.Write(data2);
}

using (var stream = new BufferedStream(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize: 0)))
{
stream.Seek(position1, SeekOrigin.Begin);
Assert.Equal(buffer.Length, stream.Read(buffer));
Assert.Equal(data1, buffer);

stream.Seek(position2, SeekOrigin.Begin);
Assert.Equal(buffer.Length, stream.Read(buffer));
Assert.Equal(data2, buffer);
}
}
}

public class BufferedStream_TestLeaveOpen : TestLeaveOpen
Expand Down