-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Fix Position and Seek for MemoryStream with custom origin #88572
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
@@ -82,6 +84,34 @@ public static void MemoryStream_WriteToTests_Negative() | |
} | ||
} | ||
|
||
public static IEnumerable<object[]> MemoryStream_PositionOverflow_Throws_MemberData() => | ||
from mode in Enum.GetValues<SeekMode>() | ||
from bufferContext in | ||
new (int bufferSize, int origin)[] | ||
{ | ||
(0, 0), | ||
(1, 0), | ||
(1, 1), | ||
(10, 0), | ||
(10, 5), | ||
(10, 10), | ||
(Array.MaxLength, 0), | ||
(Array.MaxLength, Array.MaxLength) | ||
} | ||
select new object[] {mode, bufferContext.bufferSize, bufferContext.origin}; | ||
|
||
[ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.Is64BitProcess))] | ||
[MemberData(nameof(MemoryStream_PositionOverflow_Throws_MemberData))] | ||
public void MemoryStream_SeekOverflow_Throws(SeekMode mode, int bufferSize, int origin) | ||
{ | ||
byte[] buffer = new byte[bufferSize]; | ||
using (MemoryStream ms = new MemoryStream(buffer, origin, buffer.Length - origin, true)) | ||
{ | ||
Seek(mode, ms, int.MaxValue - origin); | ||
Assert.Throws<ArgumentOutOfRangeException>(() => Seek(mode, ms, (long)int.MaxValue - origin + 1)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you please test with an offset of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, removing the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added two Seek calls with |
||
} | ||
} | ||
jozkee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[Fact] | ||
public void DerivedMemoryStream_ReadWriteSpanCalled_ReadWriteArrayUsed() | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these last two cases are causing OOM on 32 bit
https://helixre107v0xdcypoyl9e7f.blob.core.windows.net/dotnet-runtime-refs-pull-88572-merge-044351d2f9494dfeb8/System.IO.Tests/1/console.f70c368a.log?helixlogtype=result