Navigation
API > API/Runtime > API/Runtime/Engine
Description
===================== Safe TArray Serialization =====================
These are helper methods intended to make serializing TArrays safer in custom NetSerialize functions. These enforce max limits on array size, so that a malformed packet is not able to allocate an arbitrary amount of memory (E.g., a hacker serilizes a packet where a TArray size is of size MAX_int32, causing gigs of memory to be allocated for the TArray).
These should only need to be used when you are overriding NetSerialize on a UStruct via struct traits. When using default replication, TArray properties already have this built in security.
SafeNetSerializeTArray_Default - calls << operator to serialize the items in the array. SafeNetSerializeTArray_WithNetSerialize - calls NetSerialize to serialize the items in the array.
When saving, bOutSuccess will be set to false if the passed in array size exceeds to MaxNum template parameter.
Example:
FMyStruct { TArray
bool NetSerialize(FArchive& Ar, class UPackageMap* Map, bool& bOutSuccess) { // Don't do this: Ar << MyFloats; Ar << MyVectors;
// Do this instead: SafeNetSerializeTArray_Default<31>(Ar, MyFloats); SafeNetSerializeTArray_WithNetSerialize<31>(Ar, MyVectors, Map); } }
| Name | SafeNetSerializeTArray_HeaderOnly |
| Type | function |
| Header File | /Engine/Source/Runtime/Engine/Classes/Engine/NetSerialization.h |
| Include Path | #include "Engine/NetSerialization.h" |
template<int32 MaxNum, typename T, typename A >
int32 SafeNetSerializeTArray_HeaderOnly
(
FArchive & Ar,
TArray < T, A > & Array,
bool & bOutSuccess
)