File tree Expand file tree Collapse file tree 2 files changed +7
-9
lines changed
Microsoft.Toolkit.HighPerformance/Streams/Sources Expand file tree Collapse file tree 2 files changed +7
-9
lines changed Original file line number Diff line number Diff line change 44
55using System ;
66using System . Runtime . CompilerServices ;
7+ #if SPAN_RUNTIME_SUPPORT
78using System . Runtime . InteropServices ;
89using Microsoft . Toolkit . HighPerformance . Extensions ;
10+ #endif
911
1012namespace Microsoft . Toolkit . HighPerformance . Streams
1113{
Original file line number Diff line number Diff line change 55using System ;
66using System . Buffers ;
77using System . Runtime . CompilerServices ;
8- using System . Runtime . InteropServices ;
9- using Microsoft . Toolkit . HighPerformance . Extensions ;
108
119namespace Microsoft . Toolkit . HighPerformance . Streams
1210{
@@ -56,13 +54,11 @@ public Span<byte> Span
5654 [ MethodImpl ( MethodImplOptions . AggressiveInlining ) ]
5755 get
5856 {
59- #if SPAN_RUNTIME_SUPPORT
60- ref byte r0 = ref this . memoryManager . GetSpan ( ) . DangerousGetReferenceAt ( this . offset ) ;
61-
62- return MemoryMarshal . CreateSpan ( ref r0 , this . length ) ;
63- #else
64- return this . memoryManager . GetSpan ( ) ;
65- #endif
57+ // We can't use the same trick we use for arrays to optimize the creation of
58+ // the offset span, as otherwise a bugged MemoryManager<T> instance returning
59+ // a span of an incorrect size could cause an access violation. Instead, we just
60+ // get the span and then slice it, which will validate both offset and length.
61+ return this . memoryManager . GetSpan ( ) . Slice ( this . offset , this . length ) ;
6662 }
6763 }
6864 }
You can’t perform that action at this time.
0 commit comments