Out-of-bounds read in ESPNOW receive handler (missing length check)
Author: TheOnionJrCreated Sep 21, 2026Updated Sep 21, 2026
EspConnection::onDataRecv() casts the incoming ESP-NOW payload directly to a Message* and copies the whole struct, without checking len against sizeof(Message).
sizeof(Message) is 264 bytes. ESP-NOW's own payload cap is 250 bytes, so len can never legitimately reach 264. Every packet received, not just malicious ones, causes the copy to read past the real buffer.
Location: src/core/connect/esp_connection.cpp, EspConnection::onDataRecv()
void EspConnection::onDataRecv(const uint8_t *mac, const uint8_t *incomingData, int len) {
Message recvMessage;
const Message *incomingMessage = reinterpret_cast<const Message *>(incomingData);
recvMessage = *incomingMessage; // copies sizeof(Message) = 264 bytes regardless of len
...Confirmed under AddressSanitizer via fuzzing: a 4-byte payload produces a 260-byte heap-buffer-overflow read.
Suggested fix:
if (len < 0 || (size_t)len < sizeof(Message)) return;before the copy.
Source: BruceDevices/firmware