From fcec146a94d848176331893cc7a5946406873e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Sch=C3=A4ffersmann?= Date: Fri, 27 Jun 2025 11:07:41 +0200 Subject: [PATCH] fix(esp32): Fix appending to Strings longer than 64k If oldLen is truncated to uint16_t, appending to a String that is longer than 65535 bytes will create a broken string. --- cores/esp32/WString.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cores/esp32/WString.cpp b/cores/esp32/WString.cpp index 18e64767545..6632aa5f85d 100644 --- a/cores/esp32/WString.cpp +++ b/cores/esp32/WString.cpp @@ -180,7 +180,7 @@ bool String::changeBuffer(unsigned int maxStrLen) { if (maxStrLen < sizeof(sso.buff) - 1) { if (isSSO() || !buffer()) { // Already using SSO, nothing to do - uint16_t oldLen = len(); + size_t oldLen = len(); setSSO(true); setLen(oldLen); } else { // if bufptr && !isSSO() @@ -188,7 +188,7 @@ bool String::changeBuffer(unsigned int maxStrLen) { char temp[sizeof(sso.buff)]; memcpy(temp, buffer(), maxStrLen); free(wbuffer()); - uint16_t oldLen = len(); + size_t oldLen = len(); setSSO(true); memcpy(wbuffer(), temp, maxStrLen); setLen(oldLen); @@ -201,7 +201,7 @@ bool String::changeBuffer(unsigned int maxStrLen) { if (newSize > CAPACITY_MAX) { return false; } - uint16_t oldLen = len(); + size_t oldLen = len(); char *newbuffer = (char *)realloc(isSSO() ? nullptr : wbuffer(), newSize); if (newbuffer) { size_t oldSize = capacity() + 1; // include NULL.