SafeNetSerializeTArray_HeaderOnly

===================== Safe [TArray](API\Runtime\Core\Containers\TArray) Serialization =====================

Windows
MacOS
Linux

References

Module

Engine

Header

/Engine/Source/Runtime/Engine/Classes/Engine/NetSerialization.h

Include

#include "Engine/NetSerialization.h"

Syntax

template<int32 MaxNum, typename T, typename A>
int32 SafeNetSerializeTArray_HeaderOnly
(
    FArchive & Ar,
    TArray< T, A > & Array,
    bool & bOutSuccess
)

Remarks

===================== 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 MyFloats; // We want to call << to serialize floats TArray MyVectors; // We want to call NetSeriailze on these *

Do this instead: SafeNetSerializeTArray_Default<31>(Ar, MyFloats); SafeNetSerializeTArray_WithNetSerialize<31>(Ar, MyVectors, Map); } }

Help shape the future of Unreal Engine documentation! Tell us how we're doing so we can serve you better.
Take our survey
Dismiss