diff --git a/wled00/json.cpp b/wled00/json.cpp index 44c2d280..ea6856d6 100644 --- a/wled00/json.cpp +++ b/wled00/json.cpp @@ -1072,7 +1072,7 @@ void setPaletteColors(JsonArray json, byte* tcp) void serializePalettes(JsonObject root, AsyncWebServerRequest* request) { - byte tcp[72]; + byte tcp[72 +4] = { 255 }; // WLEDMM bugfix - use extra element as "stop" marker (=255) for setPaletteColors(). And no, I won't cry over 4 bytes wasted ;-) #ifdef ESP8266 int itemPerPage = 5; #else @@ -1173,7 +1173,16 @@ void serializePalettes(JsonObject root, AsyncWebServerRequest* request) if (i>=palettesCount) { setPaletteColors(curPalette, strip.customPalettes[i - palettesCount]); } else { - memcpy_P(tcp, (byte*)pgm_read_dword(&(gGradientPalettes[i - 13])), 72); + // WLEDMM workaround for palettes index overflow at i=74 -> gGradientPalettes index=61 out of bounds. + int palIndex = i-13; + constexpr int palMax = sizeof(gGradientPalettes)/sizeof(gGradientPalettes[0]) -1; + if ((palIndex < 0) || (palIndex > palMax)) { + DEBUG_PRINTF("WARNING gGradientPalettes[%d] is out of bounds! max=%d. (json.cpp)\n", palIndex, palMax); + palIndex = palMax; // use last valid array item + } + memset(tcp, 255, sizeof(tcp)); // WLEDMM pre-fill buffer with dummy values, to avoid array overrun in setPaletteColors in case of "unterminated" palette entry + // WLEDMM end + memcpy_P(tcp, (byte*)pgm_read_dword(&(gGradientPalettes[palIndex])), 72); setPaletteColors(curPalette, tcp); } } diff --git a/wled00/wled.h b/wled00/wled.h index 25016a98..2dd23031 100644 --- a/wled00/wled.h +++ b/wled00/wled.h @@ -8,7 +8,7 @@ */ // version code in format yymmddb (b = daily build) -#define VERSION 2304170 +#define VERSION 2304190 //uncomment this if you have a "my_config.h" file you'd like to use //#define WLED_USE_MY_CONFIG