mirror of
https://github.com/Ryujinx/Ryujinx.git
synced 2024-11-18 18:46:39 +00:00
Avoid LM service crashes by not reading more than the buffer size (#4701)
This commit is contained in:
parent
9e50dd99d7
commit
add2a9d151
2 changed files with 11 additions and 6 deletions
|
@ -33,6 +33,11 @@ namespace Ryujinx.Common.Memory
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ReadOnlySpan<byte> GetSpanSafe(int size)
|
||||||
|
{
|
||||||
|
return GetSpan((int)Math.Min((uint)_input.Length, (uint)size));
|
||||||
|
}
|
||||||
|
|
||||||
public T ReadAt<T>(int offset) where T : unmanaged
|
public T ReadAt<T>(int offset) where T : unmanaged
|
||||||
{
|
{
|
||||||
return MemoryMarshal.Cast<byte, T>(_input.Slice(offset))[0];
|
return MemoryMarshal.Cast<byte, T>(_input.Slice(offset))[0];
|
||||||
|
|
|
@ -113,7 +113,7 @@ namespace Ryujinx.Horizon.LogManager.Ipc
|
||||||
}
|
}
|
||||||
else if (key == LogDataChunkKey.Message)
|
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)
|
if (isHeadPacket && isTailPacket)
|
||||||
{
|
{
|
||||||
|
@ -131,23 +131,23 @@ namespace Ryujinx.Horizon.LogManager.Ipc
|
||||||
}
|
}
|
||||||
else if (key == LogDataChunkKey.Filename)
|
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)
|
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)
|
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)
|
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)
|
else if (key == LogDataChunkKey.ProgramName)
|
||||||
{
|
{
|
||||||
_logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpan(size)).TrimEnd();
|
_logPacket.ProgramName = Encoding.UTF8.GetString(reader.GetSpanSafe(size)).TrimEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue