Skip to content

SAM_SPI: Fix IndexOutOfRangeException in SetDmaAccessWidth#199

Open
msarehn wants to merge 1 commit intorenode:masterfrom
MenloSystems:upstream/sam4-spi-fix-out-of-bounds-access
Open

SAM_SPI: Fix IndexOutOfRangeException in SetDmaAccessWidth#199
msarehn wants to merge 1 commit intorenode:masterfrom
MenloSystems:upstream/sam4-spi-fix-out-of-bounds-access

Conversation

@msarehn
Copy link
Copy Markdown

@msarehn msarehn commented Apr 24, 2026

When the SPI Mode Register PCS field is set to 0xF (no chip select active), ChipSelect() computes selectedSlaveAddr=4 via GetLeastSignificantZero/Logarithm2. SetDmaAccessWidth() then accesses txLengths[4] which is out of bounds for the 4-element array (indices 0-3), causing an unhandled IndexOutOfRangeException that crashes the emulation.

Guard the array access in SetDmaAccessWidth() and fall back to byte-width DMA when the computed slave register number exceeds the array bounds.

This is part of a larger effort to properly emulate SAM4E-based devices.

When the SPI Mode Register PCS field is set to 0xF (no chip select
active), ChipSelect() computes selectedSlaveAddr=4 via
GetLeastSignificantZero/Logarithm2.  SetDmaAccessWidth() then
accesses txLengths[4] which is out of bounds for the 4-element
array (indices 0-3), causing an unhandled IndexOutOfRangeException
that crashes the emulation.

Guard the array access in SetDmaAccessWidth() and fall back to
byte-width DMA when the computed slave register number exceeds the
array bounds.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 24, 2026

CLA assistant check
All committers have signed the CLA.

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