Skip to content

fix(fled): reject chromaticities that are not chromaticities (#4156 R6) - #4260

Merged
zackees merged 1 commit into
masterfrom
fix/4156-r6-chromaticity-admission
Sep 10, 2026
Merged

zackees merged 1 commit into
masterfrom
fix/4156-r6-chromaticity-admission

Conversation

@zackees

@zackees zackees commented Sep 10, 2026 •

Copy link
Copy Markdown
Member

R6's remaining half. readXy checked that a video.color primary was a two-element array of numbers — nothing about whether the pair is a chromaticity.

Two properties are now required, and neither is a matter of taste.

Ordinary numbers

A JSON literal past float range does not fail to parse here — as_float() hands back an out-of-range value, and an infinite coordinate is not a chromaticity.

Worth recording how that was confirmed, because the obvious probe lies. FL_WARN printed the value as -21474836.48 for every over-range input:

PROBE {"v":[1e400,0.33]} has=1 v=-21474836.48 nan=0 huge=1
PROBE {"v":[1e39,0.33]}  has=1 v=-21474836.48 nan=0 huge=1
PROBE {"v":[1e300,0.33]} has=1 v=-21474836.48 nan=0 huge=1

That looks like a finite number and is not — it is FL_WARN's own float formatter overflowing an int32 (-2147483648/100). The huge column, comparing against a magnitude bound, shows the value really is beyond 1e30. Reading the printed number would have led me to conclude the check was dead code and delete it.

Positive y

xyY → XYZ divides by it. At zero the primary becomes a zero column and the profile is refused later as a singular matrix — correct, but reported far from the field that caused it. A negative y is not a dimmer colour; it is not a chromaticity at all.

Deliberately not decided: the xy simplex

Primaries outside it are imaginary, wide-gamut encodings legitimately use them, and R6 says so explicitly:

Decide explicitly whether imaginary source primaries are supported rather than banning them accidentally.

No such decision exists, so a test asserts those primaries still resolve. Adding the simplex rejection fails that test — which is how the open question stays open instead of being closed as a side effect of a range check.

Mutation testing

mutation fails
finite check becomes a no-op the non-finite case
y > 0 check becomes a no-op the zero-y case
also reject outside the simplex the imaginary-primaries case

Two of these initially read as survivors: removing the finite check tripped -Werror,-Wunused-function, the build failed, and the runner scored a stale .so at 37/37. Rewritten so they compile, both die correctly. Same trap as earlier in this program — a mutation that does not build is not a mutation that survived.

Verification

  • bash test --cpp — 299/299 unit, 84/84 examples
  • bash lint — clean, exit 0

Refs #4156

🤖 Generated with Claude Code

https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9

Summary by CodeRabbit

  • Bug Fixes

    • Custom color primaries now reject non-finite chromaticity values.
    • Custom primaries with zero or negative y-coordinates are reported as malformed.
    • Valid custom primaries outside the xy simplex continue to be accepted.
  • Tests

    • Added coverage for invalid chromaticity coordinates and accepted out-of-simplex primaries.

R6's remaining half: `readXy` checked that a `video.color` primary was a
two-element array of numbers and nothing else. Two properties are now
required, and neither is a matter of taste.

**Ordinary numbers.** A JSON literal past float range does not fail to parse
here -- `as_float()` hands back an out-of-range value, and an infinite
coordinate is not a chromaticity.

Worth recording how that was confirmed, because the obvious probe lies:
`FL_WARN` printed the value as `-21474836.48` for every over-range input,
which looks like a finite number and is not. That is its own float formatter
overflowing an int32; comparing against a magnitude bound in the test shows
the value really is beyond 1e30. Reading the printed number would have led to
the wrong conclusion.

**Positive `y`.** xyY -> XYZ divides by it. At zero the primary becomes a zero
column, and the profile is refused later as a singular matrix -- correct, but
reported far from the field that caused it. A negative `y` is not a dimmer
colour, it is not a chromaticity at all.

**Deliberately not decided: the xy simplex.** Primaries outside it are
imaginary, wide-gamut encodings legitimately use them, and R6 asks for that to
be an explicit decision rather than the side effect of a range check. No
decision exists, so a test asserts such primaries still resolve -- adding the
simplex rejection fails it, which is how the open question stays open instead
of being closed by accident.

Mutation-tested, each against its own case. Two of those mutations initially
read as survivors: removing the finite check tripped
`-Werror,-Wunused-function`, the build failed, and the runner scored a stale
`.so` at 37/37. Rewritten so they compile, both die correctly.

Refs #4156

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
@coderabbitai

coderabbitai Bot commented Sep 10, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 09faaf85-4fed-4480-a496-09ae0cb9af6b

📥 Commits

Reviewing files that changed from the base of the PR and between 77c050a and b81eb14.

📒 Files selected for processing (2)
  • src/fl/fled/color.cpp.hpp
  • tests/fl/fled/fled_color.cpp

Included review availability: Your plan provides up to 8 included reviews per hour; 1 remains after this review.


📝 Walkthrough

Walkthrough

The custom-primary coordinate parser now rejects non-finite values and non-positive y values. Tests cover these cases and confirm that coordinates outside the xy simplex remain accepted.

Changes

Custom primaries validation

Layer / File(s) Summary
Numeric coordinate validation
src/fl/fled/color.cpp.hpp
readXy rejects non-finite coordinates and non-positive y values before storing the pair.
Validation contract tests
tests/fl/fled/fled_color.cpp
Tests cover invalid y values, non-finite coordinates, and accepted imaginary primaries.

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

Merge Risk: ⚪ Minimal · up to b81eb

Custom color primaries with invalid numeric coordinates are now rejected safely, while supported out-of-simplex primaries remain accepted. The validation behavior is covered by tests and is ready to merge.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: rejecting invalid chromaticity coordinates in fled.
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.
  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/4156-r6-chromaticity-admission

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

Comment @coderabbitai help to get the list of available commands.

@zackees
zackees merged commit a2f2a7f into master Sep 10, 2026
27 checks passed
@fastled-project-sync fastled-project-sync Bot moved this from Triage to Done in FastLED Tracker Sep 10, 2026
@zackees
zackees deleted the fix/4156-r6-chromaticity-admission branch November 5, 2026 05:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant