Skip to content

Commit

Permalink
Move NoInt32OverflowInTheBufferingLogic to OuterLoop and address pend…
Browse files Browse the repository at this point in the history
…ing feedback (dotnet#60606)
  • Loading branch information
jozkee committed Dec 21, 2021
1 parent 818daa9 commit 04af7ae
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/libraries/System.IO.FileSystem/tests/FileStream/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public void NegativeReadRootThrows()
new FileStream(Path.GetPathRoot(Directory.GetCurrentDirectory()), FileMode.Open, FileAccess.Read));
}

[ConditionalFact(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))]
[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

0 comments on commit 04af7ae

Please sign in to comment.