Skip to content
Merged
Changes from 1 commit
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
Next Next commit
add a failing test
  • Loading branch information
adamsitnik authored and github-actions committed Oct 15, 2021
commit c8f04592459a8f8b6f138d346d5e3ad6a1d3691a
34 changes: 34 additions & 0 deletions src/libraries/System.IO.FileSystem/tests/FileStream/Read.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,39 @@ public void NegativeReadRootThrows()
Assert.Throws<UnauthorizedAccessException>(() =>
new FileStream(Path.GetPathRoot(Directory.GetCurrentDirectory()), FileMode.Open, FileAccess.Read));
}

[Fact]
public void NoInt32OverflowInTheBufferingLogic()
{
const long positon1 = 10;
const long positon2 = (1L << 32) + positon1;

string filePath = GetTestFilePath();
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(positon1, SeekOrigin.Begin);
stream.Write(data1, 0, data1.Length);

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

using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
stream.Seek(positon1, SeekOrigin.Begin);
Assert.Equal(buffer.Length, stream.Read(buffer));
Assert.Equal(data1, buffer);

Array.Clear(buffer);

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