Skip to content

cli: stop applying out-of-range zone size in --size handler#101

Open
jbetala7 wants to merge 1 commit into
CalcProgrammer1:masterfrom
jbetala7:oss/fix-cli-size-out-of-range-guard
Open

cli: stop applying out-of-range zone size in --size handler#101
jbetala7 wants to merge 1 commit into
CalcProgrammer1:masterfrom
jbetala7:oss/fix-cli-size-out-of-range-guard

Conversation

@jbetala7

Copy link
Copy Markdown

Problem

OptionSize() (the --size CLI handler) validates the requested zone size against the zone's leds_min/leds_max, but the out-of-range branch only prints an error and then falls through — it does not stop like the two sibling validation branches do.

if((current_device >= ...) || (current_device < 0))
{
    std::cout << "Error: Device is out of range" << std::endl;
    return false;                       // aborts
}
else if((current_zone >= ...) || (current_zone < 0))
{
    std::cout << "Error: Zone is out of range" << std::endl;
    return false;                       // aborts
}
else if((new_size < ...leds_min) || (new_size > ...leds_max))
{
    std::cout << "Error: New size is out of range" << std::endl;
    // <-- no return; execution continues
}

rgb_controllers[current_device]->ResizeZone(current_zone, new_size);   // runs anyway
...SaveProfile("sizes", true);                                          // and is persisted

So a size that was explicitly rejected as out of range is still passed to ResizeZone() and then written to the sizes profile.

Why this matters

RGBController::ResizeZone(int zone, int new_size) is pure-virtual and implemented per device, so this CLI bounds check is the only general guard in front of it. Bypassing it forwards an out-of-range size directly to device-specific resize code (which generally trusts the value, e.g. resizing LED vectors) and saves the bad value to the profile, so it is re-applied on the next load.

Current behavior (upstream master)

openrgb --device N --zone Z --size <out-of-range> prints Error: New size is out of range and then resizes the zone to that value anyway and saves it.

Expected behavior

An out-of-range size should be rejected without resizing or saving, exactly like the device-out-of-range and zone-out-of-range cases.

Fix

Add the missing return false; to the out-of-range branch so it matches the two preceding validation branches.

         else if((new_size < ...leds_min) || (new_size > ...leds_max))
         {
             std::cout << "Error: New size is out of range" << std::endl;
+            return false;
         }

Verification

Verified by inspection: the change makes the third validation branch structurally identical to the two sibling branches in the same function that already return false. The buggy fall-through into ResizeZone() + SaveProfile() is removed for rejected sizes; valid sizes are unaffected. (A full runtime test of --size requires target RGB hardware, so it was not exercised on real devices.)

Duplicate / collision check

No open or recently-closed PR touches cli.cpp's OptionSize or the size-bounds logic (open PRs in the area are device-specific or GUI, e.g. #87 Razer SetupZones, #29 color-picker cursor bounds).

Note: this repository is a one-way mirror of GitLab with issues disabled, so the bug report is documented here rather than in a linked issue.

🤖 Generated with Claude Code

OptionSize() validates the requested zone size against the zone's
leds_min/leds_max, but unlike the sibling device-out-of-range and
zone-out-of-range checks it only printed "Error: New size is out of
range" and then fell through, calling ResizeZone(current_zone,
new_size) with the rejected value and persisting it via SaveProfile().

Since RGBController::ResizeZone() is a pure-virtual implemented per
device, the CLI bounds check is the only general guard, so the bypass
forwards an out-of-range size straight to device resize code and saves
it to the "sizes" profile.

Return false on the out-of-range branch, matching the two preceding
validation branches, so an invalid size is neither applied nor saved.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant