Skip to content

fix(channels): guard Channel::applyAddressing against zero-width XYMap and OOM - #5496

Merged
zackees merged 1 commit into
masterfrom
fix/channel-addressing-oom-zero-width
Dec 3, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/channel-addressing-oom-zero-width

Conversation

@zackees

@zackees zackees commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Implements #5492 item #13.

  • Return early in ReorderingPixelIteratorAny::applyAddressing() if width == 0, height == 0, or numLeds == 0, preventing divide-by-zero in physicalIdx % width / physicalIdx / width.
  • Compute expectedLeds in u32 to avoid u16 multiplication overflow.
  • Check buffer.size() == numLeds after buffer.resize(numLeds) so an allocation failure logs an error and falls back to the un-reordered pixels instead of writing out of bounds.

Verification

  • bash lint src/fl/channels/channel.cpp.hpp tests/unit/fl/channels/channel.cpp — passed
  • bash test channel --debug (ASAN/LSAN/UBSAN) — passed (including new zero-width XYMap regression test)

Summary by CodeRabbit

  • Bug Fixes
    • Prevented errors when displaying pixels with empty or mismatched XY maps. In these cases, the original pixels are preserved.
    • Improved handling of large maps to avoid incorrect pixel counts.

@coderabbitai

coderabbitai Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Explain Change →

Note

.coderabbit.yaml has unrecognized properties

CodeRabbit is using all valid settings from your configuration. Unrecognized properties (listed below) have been ignored and may indicate typos or deprecated fields that can be removed.

Parsing warnings: 1

Validation error: Unrecognized key: "enabled" at "reviews.pre_merge_checks"
Configuration instructions

  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Walkthrough

applyAddressing now bypasses XYMap reordering for zero dimensions or a zero LED count. It calculates the expected map size with 32-bit multiplication and checks the resized buffer size. A unit test verifies that a zero-width map preserves both input pixels.

Changes: XYMap Reordering

Layer / File(s) Summary
Reordering guards and regression test
src/fl/channels/channel.cpp.hpp, tests/unit/fl/channels/channel.cpp
applyAddressing returns the original pixels when map dimensions or LED count are zero, or when the resized reorder buffer does not match the LED count. The expected map size uses 32-bit multiplication. A unit test checks that showing a channel with a zero-width map preserves both input pixels.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 0113b

This change prevents a divide-by-zero and an overflow-related allocation problem when a channel is given an invalid zero-sized map. The affected path now falls back to the original pixels. Tests cover the zero-width case, and no merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: guarding Channel::applyAddressing against a zero-width XYMap and against out-of-memory conditions. The raw summary describes exactly this: an early return for zero map…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: guarding Channel::applyAddressing against a zero-width XYMap and against out-of-memory conditions. The raw summary describes exactly this: an early return for zero map dimensions or LED count, a 32-bit expected-LED calculation to avoid overflow, and an error-logging fallback when the resized buffer has the wrong size. The added regression test for a zero-width XYMap also matches the title. The title is specific and follows the conventional-commit style, so it passes.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Additional comments: 1

tests/unit/fl/channels/channel.cpp-1925-1925: 1

1925-1925: Minor · Maintainability & Code Quality · Quick win

Unverified finding
Verification ran but could not confirm this finding. It is shown for review, not as a verified issue.

Use a real host driver in the new regression test.

ByteCapturingMockEngine is a mock driver. Use a real host driver and observe the production encoded data, while retaining the exact byte assertion.

As per coding guidelines, “No mocks — test real implementations.”

Source: Coding guidelines

Review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between a1789a4 and 0113b17.

Files selected for processing: 2

  • src/fl/channels/channel.cpp.hpp
  • tests/unit/fl/channels/channel.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.

@zackees
zackees added this pull request to the merge queue Dec 3, 2026
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Memory usage (this PR vs. its merge base)

Change in examples/Blink per target. The left number is this PR's image flash / attributed RAM in bytes; the colored delta is the change from the merge base (red ↑ is larger, green ↓ is smaller, Same is unchanged).

Target FLASH [bytes] RAM [bytes]
attiny85 2,460 (Same) 136 (Same)

@fastled-project-sync fastled-project-sync Bot moved this to Triage in FastLED Tracker Dec 3, 2026
Merged via the queue into master with commit 87e14ec Dec 3, 2026
134 checks passed
@zackees
zackees deleted the fix/channel-addressing-oom-zero-width branch December 3, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

1 participant