diff --git a/Ryujinx.Common/Memory/SpanReader.cs b/Ryujinx.Common/Memory/SpanReader.cs index e46649e1c..673932d0b 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]; diff --git a/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs b/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs index 8b3acb101..e930bdd75 100644 --- a/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs +++ b/Ryujinx.Horizon/LogManager/Ipc/LmLogger.cs @@ -113,7 +113,7 @@ namespace Ryujinx.Horizon.LogManager.Ipc } else if (key == LogDataChunkKey.Message) { - string text = Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd(); + string text = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); if (isHeadPacket && isTailPacket) { @@ -131,23 +131,23 @@ namespace Ryujinx.Horizon.LogManager.Ipc } else if (key == LogDataChunkKey.Filename) { - _logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd(); + _logPacket.Filename = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); } else if (key == LogDataChunkKey.Function) { - _logPacket.Function = Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd(); + _logPacket.Function = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); } else if (key == LogDataChunkKey.Module) { - _logPacket.Module = Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd(); + _logPacket.Module = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); } else if (key == LogDataChunkKey.Thread) { - _logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd(); + _logPacket.Thread = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); } else if (key == LogDataChunkKey.ProgramName) { - _logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd(); + _logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd(); } }