From 2dd767ed3fcfd787feb84369a804de3442508acb Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 18 Feb 2026 18:10:29 -0600 Subject: [PATCH] [json] Bump heap fallback cap from 4096 to 5120 Aligns with the doubling sequence from 640: 1280 -> 2560 -> 5120. --- esphome/components/json/json_util.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/esphome/components/json/json_util.cpp b/esphome/components/json/json_util.cpp index 6ec4d657a1..d9e655c441 100644 --- a/esphome/components/json/json_util.cpp +++ b/esphome/components/json/json_util.cpp @@ -122,8 +122,8 @@ SerializationBuffer<> JsonBuilder::serialize() { // Payload exceeded stack buffer. Double the buffer and retry until it fits. // In practice, one iteration (1024 bytes) covers all known entity types. // Payloads exceeding 1024 bytes are not known to exist in real configurations. - // Cap at 4096 as a safety limit to prevent runaway allocation. - constexpr size_t max_heap_size = 4096; + // Cap at 5120 as a safety limit to prevent runaway allocation. + constexpr size_t max_heap_size = 5120; size_t heap_size = buf_size * 2; while (heap_size <= max_heap_size) { result.reallocate_heap_(heap_size - 1); @@ -134,7 +134,7 @@ SerializationBuffer<> JsonBuilder::serialize() { } heap_size *= 2; } - // Payload exceeds 4096 bytes - return truncated result + // Payload exceeds 5120 bytes - return truncated result ESP_LOGW(TAG, "JSON payload too large, truncated to %zu bytes", size); result.set_size_(size); return result;