feat: added checks for size of payload
This commit is contained in:
@@ -6,17 +6,19 @@ namespace Ragon.Core;
|
|||||||
public class EntityProperty
|
public class EntityProperty
|
||||||
{
|
{
|
||||||
public int Size { get; set; }
|
public int Size { get; set; }
|
||||||
|
public int Capacity { get; set; }
|
||||||
public bool IsDirty { get; private set; }
|
public bool IsDirty { get; private set; }
|
||||||
public bool IsFixed { get; private set; }
|
public bool IsFixed { get; private set; }
|
||||||
private byte[] _data;
|
private byte[] _data;
|
||||||
|
|
||||||
public EntityProperty(int size, bool isFixed)
|
public EntityProperty(int size, bool isFixed)
|
||||||
{
|
{
|
||||||
_data = new byte[512];
|
Capacity = 512;
|
||||||
|
|
||||||
Size = size;
|
Size = size;
|
||||||
IsFixed = isFixed;
|
IsFixed = isFixed;
|
||||||
IsDirty = true;
|
IsDirty = true;
|
||||||
|
|
||||||
|
_data = new byte[Capacity];
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReadOnlySpan<byte> Read()
|
public ReadOnlySpan<byte> Read()
|
||||||
|
|||||||
@@ -160,11 +160,19 @@ namespace Ragon.Core
|
|||||||
if (_serializer.ReadBool())
|
if (_serializer.ReadBool())
|
||||||
{
|
{
|
||||||
var property = ent.Properties[i];
|
var property = ent.Properties[i];
|
||||||
|
var size = property.Size;
|
||||||
if (!property.IsFixed)
|
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.Write(ref propertyPayload);
|
||||||
|
property.Size = size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user