From 6476260e8fc8759e96a9c4cbff499436e421b2cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mattias=20Sch=C3=A4ffersmann?= <117294155+MattiasTF@users.noreply.github.com> Date: Mon, 30 Jun 2025 12:04:11 +0200 Subject: [PATCH] fix(esp32): Fix appending to Strings longer than 64k (#11523) 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 18e647675..6632aa5f8 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.