From 2a588f309b8543dee6971df7de87b00f9e19ea4d Mon Sep 17 00:00:00 2001 From: Weixie Cui Date: Sat, 28 Mar 2026 02:21:21 +0800 Subject: [PATCH] PSStyle: validate background index against BackgroundColorMap 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. --- .../FormatAndOutput/common/PSStyle.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs b/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs index 3f927afd7d5..534f9541195 100644 --- a/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs +++ b/src/System.Management.Automation/FormatAndOutput/common/PSStyle.cs @@ -892,7 +892,7 @@ public static string MapColorPairToEscapeSequence(ConsoleColor foregroundColor, throw new ArgumentOutOfRangeException(paramName: nameof(foregroundColor)); } - if (backIndex < 0 || backIndex >= ForegroundColorMap.Length) + if (backIndex < 0 || backIndex >= BackgroundColorMap.Length) { throw new ArgumentOutOfRangeException(paramName: nameof(backgroundColor)); }