Skip to content

Commit 40d0d03

Browse files
authored
fixed signature verification for compressed binaries
1 parent 41ecd65 commit 40d0d03

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

cores/esp8266/Updater.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,24 @@ bool UpdaterClass::end(bool evenIfRemaining){
284284
_hash->begin();
285285
for (uint32_t offset = 0; offset < binSize; offset += sizeof(buff)) {
286286
auto len = std::min(sizeof(buff), binSize - offset);
287-
ESP.flashRead(_startAddress + offset, reinterpret_cast<uint32_t *>(&buff[0]), len);
288-
_hash->add(buff, len);
287+
288+
if (len % 4 == 0) {
289+
ESP.flashRead(_startAddress + offset, reinterpret_cast<uint32_t *>(&buff[0]), len);
290+
_hash->add(buff, len);
291+
}
292+
else {
293+
// Calculate padding needed to make len 4-byte aligned
294+
uint32_t padLen = (len + 3) & ~3; // Rounds up to nearest multiple of 4
295+
296+
// Temporary buffer to satisfy 4-byte alignment requirement
297+
uint8_t tempBuff[padLen] = {0};
298+
299+
// Read into the temporary buffer
300+
ESP.flashRead(_startAddress + offset, reinterpret_cast<uint32_t *>(&tempBuff[0]), padLen); // Note: ESP.flashRead size parameter might be in 4-byte words, not bytes
301+
302+
// Process only the relevant portion of the temp buffer
303+
_hash->add(tempBuff, len); // Ensure only len bytes are processed, not including the padded bytes
304+
}
289305
}
290306
_hash->end();
291307

0 commit comments

Comments
 (0)