Skip to content

PSStyle: validate background index against BackgroundColorMap#27106

Open
cuiweixie wants to merge 1 commit intoPowerShell:masterfrom
cuiweixie:fix-PSStyle-BackgroundColorMap-bounds-check
Open

PSStyle: validate background index against BackgroundColorMap#27106
cuiweixie wants to merge 1 commit intoPowerShell:masterfrom
cuiweixie:fix-PSStyle-BackgroundColorMap-bounds-check

Conversation

@cuiweixie
Copy link
Copy Markdown

Summary

Fixes FromAnsiColor so the background color index is validated against BackgroundColorMap.Length instead of ForegroundColorMap.Length, matching the map used for conversion and avoiding incorrect ArgumentOutOfRangeException behavior when the two maps differ in size.

Changes

  • In PSStyle.cs, compare backIndex to BackgroundColorMap.Length in the background branch.

Testing

  • Manual review; consider adding a unit test if ForegroundColorMap and BackgroundColorMap lengths can diverge in this codebase.

FromAnsiColor checked backgroundColor against ForegroundColorMap.Length, which could throw or allow out-of-range values when the two maps differ in length.

Use BackgroundColorMap.Length for the background bounds check.
Copilot AI review requested due to automatic review settings March 27, 2026 18:21
@cuiweixie cuiweixie requested a review from a team as a code owner March 27, 2026 18:21
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

Fixes a bounds-check bug in PSStyle.MapColorPairToEscapeSequence by validating the background color index against the background color map (instead of the foreground map), preventing incorrect ArgumentOutOfRangeException behavior if the map sizes ever diverge.

Changes:

  • Update MapColorPairToEscapeSequence to compare backIndex to BackgroundColorMap.Length.

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.

2 participants