Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b6ced69

Browse files
Ian Hayskarelz
authored andcommitted
Add tests for UMS PositionPointer overflowing
1 parent 4901a7f commit b6ced69

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/System.IO.UnmanagedMemoryStream/tests/UmsSecurityTest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public static void ChangePositionViaPointer()
2727
stream.PositionPointer = stream.PositionPointer - 1;
2828
});
2929

30+
Assert.Throws<ArgumentOutOfRangeException>(() => stream.PositionPointer = (byte*)ulong.MaxValue);
31+
3032
// Make sure that moving later than the length can be done but then
3133
// fails appropriately during reads and writes, and that the stream's
3234
// data is still intact after the fact
@@ -38,6 +40,19 @@ public static void ChangePositionViaPointer()
3840
}
3941
}
4042

43+
[Fact]
44+
public static void OverflowPositionPointer()
45+
{
46+
unsafe
47+
{
48+
using (var ums = new UnmanagedMemoryStream((byte*)0x40000000, 0xB8000000))
49+
{
50+
ums.PositionPointer = (byte*)0xF0000000;
51+
Assert.Equal(0xB0000000, ums.Position);
52+
}
53+
}
54+
}
55+
4156
static void VerifyNothingCanBeReadOrWritten(UnmanagedMemoryStream stream, Byte[] data)
4257
{
4358
// No Read

0 commit comments

Comments
 (0)