diff options
Diffstat (limited to 'ARMeilleure/Translation/PTC/PtcFormatter.cs')
| -rw-r--r-- | ARMeilleure/Translation/PTC/PtcFormatter.cs | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/ARMeilleure/Translation/PTC/PtcFormatter.cs b/ARMeilleure/Translation/PTC/PtcFormatter.cs index 753c01c8..2f7a9c21 100644 --- a/ARMeilleure/Translation/PTC/PtcFormatter.cs +++ b/ARMeilleure/Translation/PTC/PtcFormatter.cs @@ -50,7 +50,12 @@ namespace ARMeilleure.Translation.PTC T structure = default(T); Span<T> spanT = MemoryMarshal.CreateSpan(ref structure, 1); - stream.Read(MemoryMarshal.AsBytes(spanT)); + int bytesCount = stream.Read(MemoryMarshal.AsBytes(spanT)); + + if (bytesCount != Unsafe.SizeOf<T>()) + { + throw new EndOfStreamException(); + } return structure; } @@ -130,7 +135,12 @@ namespace ARMeilleure.Translation.PTC T[] item = new T[itemLength]; - stream.Read(MemoryMarshal.AsBytes(item.AsSpan())); + int bytesCount = stream.Read(MemoryMarshal.AsBytes(item.AsSpan())); + + if (bytesCount != itemLength) + { + throw new EndOfStreamException(); + } list.Add(item); } |
