From d747c15222daa65e4ad9d17d7d62463d744955e0 Mon Sep 17 00:00:00 2001 From: zoff99 Date: Tue, 9 Jan 2024 22:02:54 +0100 Subject: [PATCH] allow the large custom NGC packets to be handled also by the client --- toxcore/group_chats.c | 18 +++++++++++++++++- toxcore/group_common.h | 6 ++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/toxcore/group_chats.c b/toxcore/group_chats.c index 1851f2d068e..d82353d46dc 100644 --- a/toxcore/group_chats.c +++ b/toxcore/group_chats.c @@ -4993,6 +4993,22 @@ static bool custom_gc_packet_length_is_valid(uint16_t length, bool lossless) return true; } +/** @brief Returns false if a custom incoming (non private) packet is too large. */ +static bool custom_gc_incoming_non_private_packet_length_is_valid(uint16_t length, bool lossless) +{ + if (lossless) { + if (length > MAX_GC_CUSTOM_LOSSLESS_INCOMING_ASSEMBLED_PACKET_SIZE) { + return false; + } + } else { + if (length > MAX_GC_CUSTOM_LOSSY_PACKET_SIZE) { + return false; + } + } + + return true; +} + int gc_send_custom_private_packet(const GC_Chat *chat, bool lossless, uint32_t peer_id, const uint8_t *message, uint16_t length) { @@ -5089,7 +5105,7 @@ non_null(1, 2, 3, 4) nullable(7) static int handle_gc_custom_packet(const GC_Session *c, const GC_Chat *chat, const GC_Peer *peer, const uint8_t *data, uint16_t length, bool lossless, void *userdata) { - if (!custom_gc_packet_length_is_valid(length, lossless)) { + if (!custom_gc_incoming_non_private_packet_length_is_valid(length, lossless)) { return -1; } diff --git a/toxcore/group_common.h b/toxcore/group_common.h index 49c21369258..4b492bbe585 100644 --- a/toxcore/group_common.h +++ b/toxcore/group_common.h @@ -45,6 +45,12 @@ /* Max size of a complete encrypted packet including headers. */ #define MAX_GC_PACKET_SIZE (MAX_GC_PACKET_CHUNK_SIZE * 100) +/* allow incoming NGC custom packets that are non private to be up to the total max size of MAX_GC_PACKET_SIZE + * which is 50000 bytes. the data itself can only be less than that because of NGC header overhead + */ +#define MAX_GC_CUSTOM_LOSSLESS_INCOMING_ASSEMBLED_PACKET_SIZE MAX_GC_PACKET_SIZE + + /* Max number of messages to store in the send/recv arrays */ #define GCC_BUFFER_SIZE 8192