Skip to content

Fix radio receive buffer overflow at the maximum length - #147

Merged
microbit-matt-hillsdon merged 1 commit into
mainfrom
fix-radio-max-length-buffer
Nov 12, 2026
Merged

microbit-matt-hillsdon merged 1 commit into
mainfrom
fix-radio-max-length-buffer

Conversation

@microbit-matt-hillsdon

Copy link
Copy Markdown
Contributor

The receive buffer size was held in a uint8_t, so the 6 bytes of packet overhead wrapped it for the two largest values radio.config accepts. With length=251 the buffer was 1 byte and an incoming packet of up to 257 bytes was written over the MicroPython heap, which could trap with "memory access out of bounds" in qstr_find_strn on the next radio.receive(). With length=250 the size was 0, no buffer was allocated and every radio call raised "radio is not enabled".

The device's driver does this arithmetic in size_t and is unaffected.

Example failing program in the test. If you change to config(length=250) it gives the radio not enabled message.

The receive buffer size was held in a uint8_t, so the 6 bytes of packet
overhead wrapped it for the two largest values radio.config accepts.
With length=251 the buffer was 1 byte and an incoming packet of up to
257 bytes was written over the MicroPython heap, which could trap with
"memory access out of bounds" in qstr_find_strn on the next
radio.receive(). With length=250 the size was 0, no buffer was
allocated and every radio call raised "radio is not enabled".

The device's driver does this arithmetic in size_t and is unaffected.
@github-actions

Copy link
Copy Markdown

@microbit-robert microbit-robert left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@microbit-matt-hillsdon
microbit-matt-hillsdon merged commit 71e881f into main Nov 12, 2026
2 checks passed
@microbit-matt-hillsdon
microbit-matt-hillsdon deleted the fix-radio-max-length-buffer branch November 12, 2026 09:34
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.

2 participants