Skip to content

fix: reject invalid pin mappings in parallel software SPI helpers #5063

Closed

Description

@zackees

Context

The independent public blocking parallel SPI classes compute 1u << pin from arbitrary u8 pin arguments without validating the index. All six SpiBlock1/2/4/8/16/32::setPinMapping implementations do this for clock and data. ISR 1/2/4 pin-index APIs use the same unchecked operation, including data indices in their mask variants.

On targets with 32-bit unsigned int, pin 32 or greater produces undefined shifts; on 16-bit unsigned-int targets the limit is smaller. Duplicate data pins and data/clock overlap can also make contradictory masks rather than reject the configuration. A purported 32-independent-data-plus-clock mapping cannot fit one 32-bit GPIO bank; it needs explicit rejection or a real bank model, not aliased bits.

Sources at the fixed audit baseline:

void setPinMapping(u8 data, u8 clk) FL_NO_EXCEPT {
; analogous independent bodies in spi_block_2.h, spi_block_4.h, spi_block_8.h, spi_block_16.h, spi_block_32.h, spi_isr_1.h, spi_isr_2.h and spi_isr_4.h. The six blocking bodies must not be collapsed to forwarding aliases.

These documented public classes are directly callable. ParallelDevice::begin() currently rejects both modes, so no active producer is claimed through it. ISR 8/16/32 expose raw 32-bit masks; they are not mislabeled as the same index-shift implementation, but their accepted mask contract must be assessed explicitly.

Proposal

Validate pin and mask contracts before shifting, indexing, updating configuration or writing GPIO. Represent the actual target/bank capability; fail explicitly on unsupported indices, collisions or mappings rather than wrapping/truncating them. Preserve previously valid state when reconfiguration fails.

Acceptance criteria

  • RED -> GREEN tests call each actual production blocking implementation and each ISR 1/2/4 pin-index entrypoint, including mask variants. Cover valid boundary indices, unsigned-int-width boundaries, 31/32/255, duplicate pins, data-clock overlap and failed reconfiguration followed by a valid transfer.
  • No undefined shift, incorrect-bank access or GPIO output may occur for rejected inputs. Preserve all valid mapped data bits, unrelated pins, exact clock/data edges and empty/repeated transfer behavior.
  • Assess ISR 8/16/32 raw-mask contracts separately: clock mask shape, overlap, representable bank and caller rejection where applicable. Do not falsely claim those use the same pin-index API.
  • Real supported vendor builds establish bank/operation width; host sanitizers/trace tests establish production logic only. Unsupported 32-data-plus-independent-clock configurations must not silently alias.
  • Restore the old unchecked shifts/mapping independently and require focused regressions to fail, followed by exact restoration and GREEN. Bind all independent source/configuration inputs into test: gate software SPI changes on exhaustive production-path and mutation evidence #5031.

Decisions

Group the shared invalid-mapping cause while preserving independent method coverage. This is separate from the shared hardcoded MMIO selection defect and #5050's unrelated runtime channel loop. No copied test writer or absent in-tree producer can certify these public methods.

Part of #5024.

Activity

  1. added
    sanitized
    on Nov 5, 2026
  2. zackees commented on Nov 7, 2026

    @zackees
    MemberAuthor

    #5146 covers part of this issue. It validates every SpiBlock1-32 and SpiIsr1/2/4 pin-index entry point, and ParallelDevice::begin(), before any shift. Rejected calls return false and keep the last good mapping, and unmapped blocking drivers write no GPIO.

    Still open here:

  3. moved this from Triage to Done in FastLED Trackeron Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    sanitized

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions