diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/MemoryStream.cs b/src/libraries/System.Private.CoreLib/src/System/IO/MemoryStream.cs index 53f717dfe80a4e..8e4a72439b53dd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/MemoryStream.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/MemoryStream.cs @@ -263,6 +263,8 @@ public virtual int Capacity // Special behavior if the MS isn't expandable: we don't throw if value is the same as the current capacity if (value < Length) throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_SmallCapacity); + if (value > MemStreamMaxLength) + throw new ArgumentOutOfRangeException(nameof(value), SR.ArgumentOutOfRange_Capacity); EnsureNotClosed();