PacketPeer use heap buffer for var encoding.

Used to allocate in stack (via alloca) which causes crashes when trying
to encode big variables.
The buffer grows as needed up to `encode_buffer_max_size` (which is
8MiB by default) and always in power of 2.
This commit is contained in:
Fabio Alessandrelli
2020-01-18 19:52:59 +01:00
parent d4a222cd9d
commit 534bf89976
2 changed files with 34 additions and 5 deletions

View File

@ -51,6 +51,9 @@ class PacketPeer : public Reference {
bool allow_object_decoding;
int encode_buffer_max_size;
PoolVector<uint8_t> encode_buffer;
public:
virtual int get_available_packet_count() const = 0;
virtual Error get_packet(const uint8_t **r_buffer, int &r_buffer_size) = 0; ///< buffer is GONE after next get_packet
@ -69,6 +72,9 @@ public:
void set_allow_object_decoding(bool p_enable);
bool is_object_decoding_allowed() const;
void set_encode_buffer_max_size(int p_max_size);
int get_encode_buffer_max_size() const;
PacketPeer();
~PacketPeer() {}
};