Skip to content

Check ESP-NOW bridge packet size before serialising it 🤖🤖 - #3947

Open
MarkRose wants to merge 1 commit into
meshcore-dev:devfrom
MarkRose:fix/espnow-bridge-size-check
Open

MarkRose wants to merge 1 commit into
meshcore-dev:devfrom
MarkRose:fix/espnow-bridge-size-check

Conversation

@MarkRose

Copy link
Copy Markdown

ESPNowBridge::sendPacket() writes the packet into a 246-byte stack buffer with Packet::writeTo(), which takes no destination size, and only then checks whether it fitted. A packet can serialise to 254 bytes (64-byte path, 184-byte payload, transport codes). This checks getRawLength() first and writes straight into the outgoing frame, which also drops the extra copy.

#3038 described the same write-then-check as a packet-loss issue. On the current ESP32, ESP32-S3 and ESP32-C3 builds the compiler puts the outgoing buffer right after sizingBuffer, so the up-to-8-byte overrun lands in a buffer that isn't used yet; it's still undefined behaviour and depends on stack layout.

Built for Heltec_WSL3_repeater_bridge_espnow and Heltec_v2_repeater_bridge_espnow; not tested on hardware. Written with Claude (AI), reviewed by me.

🤖 Generated with Claude Code

sendPacket() serialised the packet into a 246-byte stack buffer with
Packet::writeTo(), which takes no destination size, and only then checked
whether it fitted. A packet can serialise to 254 bytes. Check
getRawLength() first and write directly into the outgoing frame, which
also drops the extra copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant