1
0
mirror of https://github.com/esphome/esphome.git synced 2025-10-12 06:43:48 +01:00

[api] Add message size limits to prevent memory exhaustion (#10936)

This commit is contained in:
J. Nick Koston
2025-10-07 19:47:31 -05:00
committed by GitHub
parent 7682b4e9a3
commit 5aff20a624
4 changed files with 35 additions and 21 deletions

View File

@@ -18,6 +18,17 @@ namespace esphome::api {
// uncomment to log raw packets
//#define HELPER_LOG_PACKETS
// Maximum message size limits to prevent OOM on constrained devices
// Handshake messages are limited to a small size for security
static constexpr uint16_t MAX_HANDSHAKE_SIZE = 128;
// Data message limits vary by platform based on available memory
#ifdef USE_ESP8266
static constexpr uint16_t MAX_MESSAGE_SIZE = 8192; // 8 KiB for ESP8266
#else
static constexpr uint16_t MAX_MESSAGE_SIZE = 32768; // 32 KiB for ESP32 and other platforms
#endif
// Forward declaration
struct ClientInfo;