feat: added checks for size of payload

This commit is contained in:
2022-08-27 11:21:51 +04:00
parent 568a3282c3
commit 4a07424293
2 changed files with 14 additions and 4 deletions
+4 -2
View File
@@ -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<byte> Read()
+10 -2
View File
@@ -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;
}
}