Skip to content

[Bug] Startup crash: PadRight totalWidth -17 in ShowUpdateNotification when console width is too narrow #28235

Open

Description

Prerequisites

Steps to reproduce

  1. Install PowerShell 7.6.6.
  2. Set the terminal/console window to a very narrow width (or launch pwsh in a terminal emulator whose initial column count is very small).
  3. Run pwsh (or open a new PowerShell 7.6.6 tab in Windows Terminal with the narrow profile).
  4. Observe that PowerShell terminates immediately with the exception below.

Expected behavior

PowerShell should start normally. If the update notification banner cannot fit in the current console width, it should skip rendering the notification or truncate it gracefully, rather than crashing the entire process.

Actual behavior

PowerShell crashes at startup with `ArgumentOutOfRangeException` and exits with code `2148734499 (0x80131623)`. The process is terminated before any prompt appears, so the user cannot use the shell to fix the issue.

Stack trace:

totalWidth ('-17') must be a non-negative value. (Parameter 'totalWidth')
Actual value was -17.
   at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)
   at System.String.PadRight(Int32 totalWidth, Char paddingChar)
   at Microsoft.PowerShell.UpdatesNotification.ShowUpdateNotification(PSHostUserInterface hostUI)
   at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)


The `Environment.FailFast` call makes this a hard crash rather than a recoverable error.

Error details

Process terminated.
totalWidth ('-17') must be a non-negative value. (Parameter 'totalWidth')
Actual value was -17.
   at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)
   at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)
   at System.Environment.FailFast(System.String, System.Exception)
   at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)
   at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])

Environment data

Name                           Value
----                           -----
PSVersion                      7.6.6
PSEdition                      Core
GitCommitHash                  (unknown — crashed before startup)
OS                             Windows (exact build affected)
Platform                       Win32NT


> **Note:** `$PSVersionTable` cannot be collected from the crashing instance because the process terminates before the prompt loads. The version above is from the installer/package.

Visuals

Not applicable.

Activity

  1. wlchen1102 commented on Oct 20, 2026

    @wlchen1102

    The console width is not involved in this crash, so the reproduction steps here point in the wrong direction and may mislead triage.

    totalWidth in the exception is not the window width. It is the padding width computed from the localized notification template itself in UpdatesNotification.ShowUpdateNotification:

    int line1Length = notificationMsgTemplate.IndexOf('\n');
    int line3Length = notificationMsgTemplate.IndexOf('\n', line2Length + 1) - (line2Length + 1);
    
    // 3 represents the extra placeholder in the template
    line3Padding = line3Padding.PadRight(line1Length - line3Length + 3);

    There is no read of Console.WindowWidth / RawUI.WindowSize anywhere on this path. The value depends only on the line lengths of the localized template and the release tag, so the crash reproduces at any console size - a 200-column window crashes exactly like a 20-column one.

    For zh-Hans on 7.6.6 the shipped template gives 38 - 58 + 3 = -17, which is why the reported value is -17 regardless of the terminal geometry. Locales with a different URL length produce other values (ko-KR reports -23, zh-Hant reports -13).

    This is the same root cause as #28131, where the analysis and a fix proposal (#28236) already exist. Narrowing the window is not required to reproduce.

  2. windsBoy1 commented on Oct 20, 2026

    @windsBoy1

    PowerShell 7.6.7 no this error ,

  3. ygu8007 commented on Oct 20, 2026

    @ygu8007

    It seems that the notification of upgrade is the trigger. Because there isn't such bug in Pwsh 7.6.7 after upgrade.

  4. Sorrow-Scarlet commented on Oct 20, 2026

    @Sorrow-Scarlet

    7.6.6 same issue. But triggered when open a posh window inside win terminal it poped a msg window and crashed. But inside vscode or codium, the posh 7.6.6 is fine.

  5. nandaccio commented on Oct 20, 2026

    @nandaccio

    Clone of #28131, I would suggest closing this one to avoid adding noise to the resolution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs-TriageThe issue is new and needs to be triaged by a work group.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions