Skip to content

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

Closed

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.

  6. frogintr commented on Oct 21, 2026

    @frogintr

    This is not a console-width issue, and widening the window does not help. The failure comes from the localized resource string.

    UpdatesNotification.ShowUpdateNotification assumes the first line of the message template is the longest:

    int line1Length = notificationMsgTemplate.IndexOf('\n');
    int line2Length = notificationMsgTemplate.IndexOf('\n', line1Length + 1);
    int line3Length = notificationMsgTemplate.IndexOf('\n', line2Length + 1);
    line3Length -= line2Length + 1;
    line2Length -= line1Length + 1;
    
    line2Padding = line2Padding.PadRight(line1Length - line2Length + releaseTag.Length);
    line3Padding = line3Padding.PadRight(line1Length - line3Length + 3);

    Measured on the shipped 7.6.6 zh-Hans satellite (Microsoft.PowerShell.ConsoleHost.resources.dll, ManagedEntranceStrings.StableUpdateNotificationMessage):

    line en-US zh-Hans
    1 60 37
    2 58 24
    3 (URL, untranslated) 57 57

    Line 3 is the release URL, so it keeps its length in every locale while line 1 shrinks. With CRLF line endings IndexOf('\n') yields line1Length = 38 and line3Length = 58, so the third line computes 38 - 58 + 3 = -17 — exactly the value in the exception. The en-US template gives 60 - 57 + 3 = 6 and never fails, which is why this only hits localized users and why the console width is irrelevant.

    Repro is deterministic: PowerShell 7.6.6 (MSIX, Windows 11) with a zh-Hans UI culture. The notification for v7.6.7 (published 2026-10-13, 7-day delay elapsed on 2026-10-20) fires on every interactive start and takes the shell down through Environment.FailFast, before any profile runs. Note that v7.6.7 ships a byte-identical UpdatesNotification.cs, so upgrading does not help either.

    #28242 removes the feature on master and carries Backport-7.6.x-Approved, so the next 7.6.x servicing release should clear this. Workaround until then: set POWERSHELL_UPDATECHECK=Off before PowerShell starts.

  7. microsoft-github-policy-service commented on Oct 22, 2026

    @microsoft-github-policy-service
    Contributor

    This issue has been marked as duplicate and has not had any activity for 1 day. It has been closed for housekeeping purposes.

  8. Geekstrange commented on Oct 29, 2026

    @Geekstrange
    Author

    PowerShell 7.6.7
    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[])
    System.ArgumentOutOfRangeException: 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)

  9. kilasuit commented on Oct 29, 2026

    @kilasuit
    Collaborator

    Geekstrange (@Geekstrange) - Please update to the latest v7.6.9 release

    The Update Notification Feature, which was causing this crash was removed as part of the v7.6.8 release so you won't get this happen in future.

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.Resolution-DuplicateThe issue is a duplicate.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions