Skip to content

Commit

Permalink
Explicitly throw the OutOfMemoryException instead of relying on Share…
Browse files Browse the repository at this point in the history
…d.Rent/Array constructor. Because it can behave differently in OSX, where it supports int.MaxValue array size. (#34040)
  • Loading branch information
felipepessoto authored Mar 31, 2020
1 parent b85563d commit 562232c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private void CheckAndResizeBuffer(int sizeHint)
newSize = currentLength + sizeHint;
if ((uint)newSize > int.MaxValue)
{
newSize = int.MaxValue;
ThrowHelper.ThrowOutOfMemoryException_BufferMaximumSizeExceeded((uint)newSize);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ namespace System.Text.Json
{
internal static partial class ThrowHelper
{
[DoesNotReturn]
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowOutOfMemoryException_BufferMaximumSizeExceeded(uint capacity)
{
throw new OutOfMemoryException(SR.Format(SR.BufferMaximumSizeExceeded, capacity));
}

[DoesNotReturn]
[MethodImpl(MethodImplOptions.NoInlining)]
public static void ThrowArgumentException_DeserializeWrongType(Type type, object value)
Expand Down

0 comments on commit 562232c

Please sign in to comment.