diff --git a/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs b/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs index 080c50a065060..ce62c9cec04bf 100644 --- a/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs +++ b/src/libraries/System.Memory/src/System/Buffers/BuffersExtensions.cs @@ -115,7 +115,7 @@ public static T[] ToArray(in this ReadOnlySequence sequence) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Write(this IBufferWriter writer, ReadOnlySpan value) { - Span destination = writer.GetSpan(); + Span destination = writer.GetSpan(value.Length); // Fast path, try copying to the available memory directly if (value.Length <= destination.Length) @@ -140,7 +140,7 @@ private static void WriteMultiSegment(IBufferWriter writer, in ReadOnlySpa input = input.Slice(writeSize); if (input.Length > 0) { - destination = writer.GetSpan(); + destination = writer.GetSpan(input.Length); if (destination.IsEmpty) {