From 40d0d03eca6f4cafef2527768614e682faa28d20 Mon Sep 17 00:00:00 2001 From: David Baka Date: Mon, 25 Mar 2024 22:32:45 +0100 Subject: [PATCH 1/4] fixed signature verification for compressed binaries --- cores/esp8266/Updater.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index b4961b616d..4fa559d5ce 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -284,8 +284,24 @@ bool UpdaterClass::end(bool evenIfRemaining){ _hash->begin(); for (uint32_t offset = 0; offset < binSize; offset += sizeof(buff)) { auto len = std::min(sizeof(buff), binSize - offset); - ESP.flashRead(_startAddress + offset, reinterpret_cast(&buff[0]), len); - _hash->add(buff, len); + + if (len % 4 == 0) { + ESP.flashRead(_startAddress + offset, reinterpret_cast(&buff[0]), len); + _hash->add(buff, len); + } + else { + // Calculate padding needed to make len 4-byte aligned + uint32_t padLen = (len + 3) & ~3; // Rounds up to nearest multiple of 4 + + // Temporary buffer to satisfy 4-byte alignment requirement + uint8_t tempBuff[padLen] = {0}; + + // Read into the temporary buffer + ESP.flashRead(_startAddress + offset, reinterpret_cast(&tempBuff[0]), padLen); // Note: ESP.flashRead size parameter might be in 4-byte words, not bytes + + // Process only the relevant portion of the temp buffer + _hash->add(tempBuff, len); // Ensure only len bytes are processed, not including the padded bytes + } } _hash->end(); From 7ef2ffb593bf6fdb2aa0d9ff0cb412878eae62e5 Mon Sep 17 00:00:00 2001 From: David Baka Date: Tue, 26 Mar 2024 10:02:40 +0100 Subject: [PATCH 2/4] changed to u8 flashRead variant --- cores/esp8266/Updater.cpp | 20 ++------------------ 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index 4fa559d5ce..ef79a5cbf3 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -284,24 +284,8 @@ bool UpdaterClass::end(bool evenIfRemaining){ _hash->begin(); for (uint32_t offset = 0; offset < binSize; offset += sizeof(buff)) { auto len = std::min(sizeof(buff), binSize - offset); - - if (len % 4 == 0) { - ESP.flashRead(_startAddress + offset, reinterpret_cast(&buff[0]), len); - _hash->add(buff, len); - } - else { - // Calculate padding needed to make len 4-byte aligned - uint32_t padLen = (len + 3) & ~3; // Rounds up to nearest multiple of 4 - - // Temporary buffer to satisfy 4-byte alignment requirement - uint8_t tempBuff[padLen] = {0}; - - // Read into the temporary buffer - ESP.flashRead(_startAddress + offset, reinterpret_cast(&tempBuff[0]), padLen); // Note: ESP.flashRead size parameter might be in 4-byte words, not bytes - - // Process only the relevant portion of the temp buffer - _hash->add(tempBuff, len); // Ensure only len bytes are processed, not including the padded bytes - } + ESP.flashRead(_startAddress + offset, buff, len); + _hash->add(buff, len); } _hash->end(); From a6fd582cc8c7d5be32adb029f1ada7ec16ba6973 Mon Sep 17 00:00:00 2001 From: David Baka Date: Tue, 26 Mar 2024 14:17:32 +0100 Subject: [PATCH 3/4] removed redundant 'alignas' specifier from buff --- cores/esp8266/Updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index ef79a5cbf3..a28d6097a5 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -279,7 +279,7 @@ bool UpdaterClass::end(bool evenIfRemaining){ } // Calculate hash of the payload, 128 bytes at a time - alignas(alignof(uint32_t)) uint8_t buff[128]; + uint8_t buff[128]; _hash->begin(); for (uint32_t offset = 0; offset < binSize; offset += sizeof(buff)) { From 674587fbc81cb39e2ec9de2bc3b301ab26fade15 Mon Sep 17 00:00:00 2001 From: David Date: Tue, 26 Mar 2024 22:07:58 +0100 Subject: [PATCH 4/4] Revert "removed redundant 'alignas' specifier from buff" This reverts commit a6fd582cc8c7d5be32adb029f1ada7ec16ba6973. --- cores/esp8266/Updater.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cores/esp8266/Updater.cpp b/cores/esp8266/Updater.cpp index a28d6097a5..ef79a5cbf3 100644 --- a/cores/esp8266/Updater.cpp +++ b/cores/esp8266/Updater.cpp @@ -279,7 +279,7 @@ bool UpdaterClass::end(bool evenIfRemaining){ } // Calculate hash of the payload, 128 bytes at a time - uint8_t buff[128]; + alignas(alignof(uint32_t)) uint8_t buff[128]; _hash->begin(); for (uint32_t offset = 0; offset < binSize; offset += sizeof(buff)) {