From 78fb0b57ae9238e2671497b1f11006167bf41a27 Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 25 Sep 2022 13:00:57 +0700 Subject: [PATCH] NetworkReader.ReadBytesSegment: use .Remaining --- Assets/Mirror/Core/NetworkReader.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Mirror/Core/NetworkReader.cs b/Assets/Mirror/Core/NetworkReader.cs index bb67f3965..99367f087 100644 --- a/Assets/Mirror/Core/NetworkReader.cs +++ b/Assets/Mirror/Core/NetworkReader.cs @@ -162,8 +162,8 @@ public byte[] ReadBytes(byte[] bytes, int count) /// Read 'count' bytes allocation-free as ArraySegment that points to the internal array. public ArraySegment ReadBytesSegment(int count) { - // check if within buffer limits - if (Position + count > buffer.Count) + // ensure remaining + if (Remaining < count) { throw new EndOfStreamException($"ReadBytesSegment can't read {count} bytes because it would read past the end of the stream. {ToString()}"); }