Skip to content

[release/v7.6.1] PSStyle: validate background index against BackgroundColorMap#27263

Closed
daxian-dbw wants to merge 1 commit into
PowerShell:release/v7.6.1from
daxian-dbw:backport/release/v7.6.1/27106-27c53eaf4
Closed

[release/v7.6.1] PSStyle: validate background index against BackgroundColorMap#27263
daxian-dbw wants to merge 1 commit into
PowerShell:release/v7.6.1from
daxian-dbw:backport/release/v7.6.1/27106-27c53eaf4

Conversation

@daxian-dbw
Copy link
Copy Markdown
Member

Backport of #27106 to release/v7.6.1

Triggered by @daxian-dbw on behalf of @cuiweixie

Original CL Label: CL-General

/cc @PowerShell/powershell-maintainers

Impact

REQUIRED: Choose either Tooling Impact or Customer Impact (or both). At least one checkbox must be selected.

Tooling Impact

  • Required tooling change
  • Optional tooling change (include reasoning)

Customer Impact

  • Customer reported
  • Found internally

Fixes FromAnsiColor incorrectly raising ArgumentOutOfRangeException when validating background color index against ForegroundColorMap.Length instead of BackgroundColorMap.Length. Customers using PSStyle background colors with maps that differ in size would encounter unexpected exceptions.

Regression

REQUIRED: Check exactly one box.

  • Yes
  • No

This is not a regression.

Testing

Manual code review verified the fix uses the correct map (BackgroundColorMap) for bounds validation in the background color branch. CI will validate the change.

Risk

REQUIRED: Check exactly one box.

  • High
  • Medium
  • Low

Single-line bounds check fix — corrects which map length is used for validation. No behavioral change for valid inputs, and the fix only affects the error path when maps differ in size.

@daxian-dbw daxian-dbw added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Apr 13, 2026
Copilot AI review requested due to automatic review settings April 13, 2026 20:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backport to release/v7.6.1 of a PSStyle bounds-check fix so background color indices are validated against the background color map length, avoiding incorrect ArgumentOutOfRangeException when validating background colors.

Changes:

  • Fix background index bounds validation in PSStyle.MapColorPairToEscapeSequence to compare against BackgroundColorMap.Length.

Comment on lines +895 to 897
if (backIndex < 0 || backIndex >= BackgroundColorMap.Length)
{
throw new ArgumentOutOfRangeException(paramName: nameof(backgroundColor));
Copy link

Copilot AI Apr 13, 2026

Choose a reason for hiding this comment

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

PR description mentions fixing FromAnsiColor, but there is no FromAnsiColor implementation in this branch/repo and the actual fix is in MapColorPairToEscapeSequence. Please update the description to reference the correct method/behavior to avoid confusion during release backport tracking.

Copilot uses AI. Check for mistakes.
@daxian-dbw daxian-dbw closed this Apr 14, 2026
@daxian-dbw daxian-dbw deleted the backport/release/v7.6.1/27106-27c53eaf4 branch April 15, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants