fix: validate LED group_repeats 1-254 and tolerate raw 0xFF on parse (M11)#106
Merged
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
…(M11) group_repeats is encoded as group_repeats-1, and raw 0xFE is the firmware's infinite sentinel. The old 1-255 range let group_repeats=255 encode to 0xFE, so a request for 255 finite repeats looped forever. Cap the finite range at 254. Conversely, from_bytes decoded raw 0xFF to 256, which the constructor then rejected — so parsing a firmware-valid payload raised. Treat 0xFF (never emitted by our encoder) like the 0xFE unbounded sentinel so from_bytes never raises. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JRrm95f1qNZzDM9r2SB6KW
62a707f to
9d7134e
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
M11 —
LedFlashConfig(group_repeats=255)silently means "repeat forever" (🟠)group_repeatsis encoded asgroup_repeats - 1, and raw0xFEis the firmware's infinite sentinel. The old1..255range allowedgroup_repeats=255, which encodes to0xFE— so a request for 255 finite repeats looped forever. The finite range is now capped at 254.Converse (🟡) —
from_bytes(raw 0xFF)raisedfrom_bytesdecoded raw0xFFto256, which the constructor then rejected, so parsing a firmware-valid payload raised.0xFF(never emitted by our encoder) is now treated like the0xFEunbounded sentinel, sofrom_bytesnever raises.Test plan
uv run pytest -q→ 446 passed (3 new: 255 rejected, 254 is max finite → raw 253,from_bytes(0xFF)parses toNonewithout raising)ruff,mypyclean🤖 Generated with Claude Code