From 4a07424293f5b487544e4c0849822de9bd722437 Mon Sep 17 00:00:00 2001 From: Edmand46 Date: Sat, 27 Aug 2022 11:21:51 +0400 Subject: [PATCH] feat: added checks for size of payload --- Ragon/Sources/Entity/EntityProperty.cs | 6 ++++-- Ragon/Sources/Game/GameRoom.cs | 12 ++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Ragon/Sources/Entity/EntityProperty.cs b/Ragon/Sources/Entity/EntityProperty.cs index fe8017f..46e037c 100644 --- a/Ragon/Sources/Entity/EntityProperty.cs +++ b/Ragon/Sources/Entity/EntityProperty.cs @@ -6,17 +6,19 @@ namespace Ragon.Core; public class EntityProperty { public int Size { get; set; } + public int Capacity { get; set; } public bool IsDirty { get; private set; } public bool IsFixed { get; private set; } private byte[] _data; public EntityProperty(int size, bool isFixed) { - _data = new byte[512]; - + Capacity = 512; Size = size; IsFixed = isFixed; IsDirty = true; + + _data = new byte[Capacity]; } public ReadOnlySpan Read() diff --git a/Ragon/Sources/Game/GameRoom.cs b/Ragon/Sources/Game/GameRoom.cs index e430063..da487db 100755 --- a/Ragon/Sources/Game/GameRoom.cs +++ b/Ragon/Sources/Game/GameRoom.cs @@ -160,11 +160,19 @@ namespace Ragon.Core if (_serializer.ReadBool()) { var property = ent.Properties[i]; + var size = property.Size; if (!property.IsFixed) - property.Size = _serializer.ReadUShort(); + size = _serializer.ReadUShort(); - var propertyPayload = _serializer.ReadData(property.Size); + if (size > property.Capacity) + { + _logger.Warn($"Property {i} payload too large, size: {size}"); + continue; + } + + var propertyPayload = _serializer.ReadData(size); property.Write(ref propertyPayload); + property.Size = size; } }