From add2a9d15120185166adc6d2431ffee7d8a8b26b Mon Sep 17 00:00:00 2001 From: gdkchan Date: Thu, 20 Apr 2023 12:10:17 -0300 Subject: Avoid LM service crashes by not reading more than the buffer size (#4701) --- Ryujinx.Common/Memory/SpanReader.cs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Ryujinx.Common/Memory') diff --git a/Ryujinx.Common/Memory/SpanReader.cs b/Ryujinx.Common/Memory/SpanReader.cs index e46649e1..673932d0 100644 --- a/Ryujinx.Common/Memory/SpanReader.cs +++ b/Ryujinx.Common/Memory/SpanReader.cs @@ -33,6 +33,11 @@ namespace Ryujinx.Common.Memory return data; } + public ReadOnlySpan GetSpanSafe(int size) + { + return GetSpan((int)Math.Min((uint)_input.Length, (uint)size)); + } + public T ReadAt(int offset) where T : unmanaged { return MemoryMarshal.Cast(_input.Slice(offset))[0]; -- cgit v1.2.3