Make LM skip instead of crashing for invalid messages (#5290)

This commit is contained in:
gdkchan
2023-06-12 21:12:06 -03:00
committed by GitHub
parent 52aa4b6c22
commit cf4c78b9c8
2 changed files with 49 additions and 14 deletions

View File

@ -24,6 +24,24 @@ namespace Ryujinx.Common.Memory
return value;
}
public bool TryRead<T>(out T value) where T : unmanaged
{
int valueSize = Unsafe.SizeOf<T>();
if (valueSize > _input.Length)
{
value = default;
return false;
}
value = MemoryMarshal.Cast<byte, T>(_input)[0];
_input = _input.Slice(valueSize);
return true;
}
public ReadOnlySpan<byte> GetSpan(int size)
{
ReadOnlySpan<byte> data = _input.Slice(0, size);