Skip to content

Commit 661a0cd

Browse files
authored
Move NoInt32OverflowInTheBufferingLogic to OuterLoop and address pending feedback (#60606)
1 parent f40d005 commit 661a0cd

File tree

2 files changed

+37
-13
lines changed

2 files changed

+37
-13
lines changed

src/libraries/System.IO.FileSystem/tests/FileStream/Read.cs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public void NegativeReadRootThrows()
1616
}
1717

1818
[Fact]
19+
[OuterLoop]
1920
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
2021
public void NoInt32OverflowInTheBufferingLogic()
2122
{
@@ -30,10 +31,10 @@ public void NoInt32OverflowInTheBufferingLogic()
3031
using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
3132
{
3233
stream.Seek(position1, SeekOrigin.Begin);
33-
stream.Write(data1, 0, data1.Length);
34+
stream.Write(data1);
3435

3536
stream.Seek(position2, SeekOrigin.Begin);
36-
stream.Write(data2, 0, data2.Length);
37+
stream.Write(data2);
3738
}
3839

3940
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
@@ -46,17 +47,6 @@ public void NoInt32OverflowInTheBufferingLogic()
4647
Assert.Equal(buffer.Length, stream.Read(buffer));
4748
Assert.Equal(data2, buffer);
4849
}
49-
50-
using (var stream = new BufferedStream(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize: 0)))
51-
{
52-
stream.Seek(position1, SeekOrigin.Begin);
53-
Assert.Equal(buffer.Length, stream.Read(buffer));
54-
Assert.Equal(data1, buffer);
55-
56-
stream.Seek(position2, SeekOrigin.Begin);
57-
Assert.Equal(buffer.Length, stream.Read(buffer));
58-
Assert.Equal(data2, buffer);
59-
}
6050
}
6151
}
6252
}

src/libraries/System.IO/tests/BufferedStream/BufferedStreamTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,40 @@ public async Task CopyToTest_ReadBeforeCopy_CopiesAllData(bool copyAsynchronousl
323323
Array.Copy(data, 1, expected, 0, expected.Length);
324324
Assert.Equal(expected, dst.ToArray());
325325
}
326+
327+
[Fact]
328+
[OuterLoop]
329+
[ActiveIssue("https://github.com/dotnet/runtime/issues/45954", TestPlatforms.Browser)]
330+
public void NoInt32OverflowInTheBufferingLogic()
331+
{
332+
const long position1 = 10;
333+
const long position2 = (1L << 32) + position1;
334+
335+
string filePath = Path.GetTempFileName();
336+
byte[] data1 = new byte[] { 1, 2, 3, 4, 5 };
337+
byte[] data2 = new byte[] { 6, 7, 8, 9, 10 };
338+
byte[] buffer = new byte[5];
339+
340+
using (var stream = new FileStream(filePath, FileMode.Create, FileAccess.Write))
341+
{
342+
stream.Seek(position1, SeekOrigin.Begin);
343+
stream.Write(data1);
344+
345+
stream.Seek(position2, SeekOrigin.Begin);
346+
stream.Write(data2);
347+
}
348+
349+
using (var stream = new BufferedStream(new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.None, bufferSize: 0)))
350+
{
351+
stream.Seek(position1, SeekOrigin.Begin);
352+
Assert.Equal(buffer.Length, stream.Read(buffer));
353+
Assert.Equal(data1, buffer);
354+
355+
stream.Seek(position2, SeekOrigin.Begin);
356+
Assert.Equal(buffer.Length, stream.Read(buffer));
357+
Assert.Equal(data2, buffer);
358+
}
359+
}
326360
}
327361

328362
public class BufferedStream_TestLeaveOpen : TestLeaveOpen

0 commit comments

Comments
 (0)