Title: PowerShell can crash on startup when displaying the update notification under zh-Hans due to negative PadRight width · Issue #28131 · PowerShell/PowerShell · GitHub
Open Graph Title: PowerShell can crash on startup when displaying the update notification under zh-Hans due to negative PadRight width · Issue #28131 · PowerShell/PowerShell
X Title: PowerShell can crash on startup when displaying the update notification under zh-Hans due to negative PadRight width · Issue #28131 · PowerShell/PowerShell
Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerShell 5.1 and PowerShell. Steps to reprodu...
Open Graph Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
X Description: Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/28131
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"PowerShell can crash on startup when displaying the update notification under zh-Hans due to negative PadRight width","articleBody":"### Prerequisites\n\n- [x] Write a descriptive title.\n- [x] Make sure you are able to repro it on the [latest released version](https://github.com/PowerShell/PowerShell/releases)\n- [x] Search the existing issues.\n- [x] Refer to the [FAQ](https://github.com/PowerShell/PowerShell/blob/master/docs/FAQ.md).\n- [x] Refer to [Differences between Windows PowerShell 5.1 and PowerShell](https://learn.microsoft.com/powershell/scripting/whats-new/differences-from-windows-powershell).\n\n### Steps to reproduce\n\nThe problem occurs in the update-notification formatting path when the UI culture is `zh-Hans`.\n\nI originally encountered the crash with PowerShell `7.7.0-preview.4` when a newer preview release became eligible for notification.\n\nThe relevant code is in:\n\n`src/Microsoft.PowerShell.ConsoleHost/host/msh/UpdatesNotification.cs`\n\ninside `UpdatesNotification.ShowUpdateNotification()`:\n\n```csharp\n// The first line is longest, if the message changes, this needs to be updated\nint line1Length = notificationMsgTemplate.IndexOf('\\n');\nint line2Length = notificationMsgTemplate.IndexOf('\\n', line1Length + 1);\nint line3Length = notificationMsgTemplate.IndexOf('\\n', line2Length + 1);\n\nline3Length -= line2Length + 1;\nline2Length -= line1Length + 1;\n\nline2Padding = line2Padding.PadRight(\n line1Length - line2Length + releaseTag.Length\n);\n\n// 3 represents the extra placeholder in the template\nline3Padding = line3Padding.PadRight(\n line1Length - line3Length + 3\n);\n```\n\nThe code assumes that the first line of the localized notification is the longest.\n\nHowever, the Simplified Chinese resource in:\n\n`src/Microsoft.PowerShell.ConsoleHost/resources/zh-Hans/ManagedEntranceStrings.zh-Hans.resx`\n\ncontains the following `PreviewUpdateNotificationMessage`:\n\n```text\n {1} 有新的 PowerShell 预览版本可用: v{0} {2}\n {1} 立即升级,或访问发布页:{3}{2}\n {1} https://aka.ms/PowerShell-Release?tag=v{0} {4}{2}\n```\n\nThe issue can be reproduced independently from the notification state with:\n\n```powershell\n$lines = @(\n ' {1} 有新的 PowerShell 预览版本可用: v{0} {2}'\n ' {1} 立即升级,或访问发布页:{3}{2}'\n ' {1} https://aka.ms/PowerShell-Release?tag=v{0} {4}{2}'\n)\n\n$lines | ForEach-Object { $_.Length }\n\n# 37\n# 24\n# 57\n\n$paddingWidth = $lines[0].Length - $lines[2].Length + 3\n$paddingWidth\n\n# -17\n\n''.PadRight($paddingWidth)\n```\n\nThis produces the same invalid padding width seen in the startup crash:\n\n```text\n-17\n```\n\nThe exact calculation performed by `ShowUpdateNotification()` is:\n\n```text\nline1Length - line3Length + 3\n= 37 - 57 + 3\n= -17\n```\n\nTherefore it eventually attempts the equivalent of:\n\n```csharp\nstring.Empty.PadRight(-17)\n```\n\nwhich throws `ArgumentOutOfRangeException`.\n\nThe same formatting logic and the same `zh-Hans` resource text are still present in the latest preview release, `v7.7.0-preview.5`.\n\nWhen an eligible update notification is actually shown, the startup failure is:\n\n```text\nProcess terminated.\ntotalWidth ('-17') must be a non-negative value. (Parameter 'totalWidth')\nActual value was -17.\n\n at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)\n at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)\n at System.Environment.FailFast(System.String, System.Exception)\n at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)\n at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])\nSystem.ArgumentOutOfRangeException: totalWidth ('-17') must be a non-negative value. (Parameter 'totalWidth')\nActual value was -17.\n at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)\n at System.String.PadRight(Int32 totalWidth, Char paddingChar)\n at Microsoft.PowerShell.UpdatesNotification.ShowUpdateNotification(PSHostUserInterface hostUI)\n at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)\n at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)\n```\n\nSetting:\n\n```cmd\nsetx POWERSHELL_UPDATECHECK Off\n```\n\navoids the crash by preventing the update-notification path from running.\n\n---\n\n### Expected behavior\n\nPowerShell should start normally and display the localized update notification.\n\nNotification formatting should work regardless of the relative lengths of localized message lines.\n\n### Actual behavior\n\nWhen the `zh-Hans` update notification is displayed, `ShowUpdateNotification()` calculates a negative padding width because the third line is longer than the first line.\n\nFor the preview notification resource:\n\n```text\nline 1 length = 37\nline 3 length = 57\n```\n\nso:\n\n```text\n37 - 57 + 3 = -17\n```\n\nThis value is passed to `String.PadRight()`, which throws `ArgumentOutOfRangeException`.\n\nBecause this happens during console-host startup, the PowerShell process terminates instead of opening an interactive session.\n\nThe underlying assumption appears to be this comment in `UpdatesNotification.cs`:\n\n```csharp\n// The first line is longest, if the message changes, this needs to be updated\n```\n\nThat assumption is not valid for all localized resources.\n\n### Error details\n\n```console\n`Get-Error` cannot be collected from the affected process because the exception occurs during PowerShell console-host startup and the process terminates through `Environment.FailFast()` before an interactive session is available.\n\nThe verbatim startup output is:\n\n\nProcess terminated.\ntotalWidth ('-17') must be a non-negative value. (Parameter 'totalWidth')\nActual value was -17.\n\n at System.Environment.FailFast(System.Runtime.CompilerServices.StackCrawlMarkHandle, System.String, System.Runtime.CompilerServices.ObjectHandleOnStack, System.String)\n at System.Environment.FailFast(System.Threading.StackCrawlMark ByRef, System.String, System.Exception, System.String)\n at System.Environment.FailFast(System.String, System.Exception)\n at Microsoft.PowerShell.UnmanagedPSEntry.Start(System.String[], Int32)\n at Microsoft.PowerShell.ManagedPSEntry.Main(System.String[])\nSystem.ArgumentOutOfRangeException: totalWidth ('-17') must be a non-negative value. (Parameter 'totalWidth')\nActual value was -17.\n at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)\n at System.String.PadRight(Int32 totalWidth, Char paddingChar)\n at Microsoft.PowerShell.UpdatesNotification.ShowUpdateNotification(PSHostUserInterface hostUI)\n at Microsoft.PowerShell.ConsoleHost.Start(String bannerText, String helpText, Boolean issProvidedExternally)\n at Microsoft.PowerShell.UnmanagedPSEntry.Start(String[] args, Int32 argc)\n```\n\n### Environment data\n\n```powershell\nPASTE THE VERBATIM OUTPUT OF:\n\n$PSVersionTable\n```\n\nThe original startup crash was observed with:\n\n```text\nPowerShell 7.7.0-preview.4\n```\n\nThe relevant implementation and `zh-Hans` resource remain unchanged in `v7.7.0-preview.5`.\n\n### Visuals\n\nNot required. The failure occurs during console-host startup and is fully represented by the stack trace above.","author":{"url":"https://github.com/Perxenic-Acid","@type":"Person","name":"Perxenic-Acid"},"datePublished":"2026-09-30T04:44:02Z","url":"https://github.com/PowerShell/PowerShell/issues/28131"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ccd394f1-6345-12b1-608a-a31c88534a49 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BBDE:F08E5:41C49:5C115:6AFCD8F2 |
| html-safe-nonce | 98670ec7bc3de81b33bfabf6947043baa624effea67b1c44568302a631dea0d2 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCQkRFOkYwOEU1OjQxQzQ5OjVDMTE1OjZBRkNEOEYyIiwidmlzaXRvcl9pZCI6IjU2MzAyODc5MzczODQ3OTg0NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 035fbcad4c78e5216ddffd559a0f8e54505aa0ad95f7d2d857231cd41d544cbf |
| hovercard-subject-tag | issue:5641051647 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/28131/issue_layout |
| twitter:image | https://opengraph.githubassets.com/13d883e2d2df7d487d31a80a379d4b7f82a0525264c954e4b8b214b3f98d35a5/PowerShell/PowerShell/issues/28131 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/13d883e2d2df7d487d31a80a379d4b7f82a0525264c954e4b8b214b3f98d35a5/PowerShell/PowerShell/issues/28131 |
| og:image:alt | Prerequisites Write a descriptive title. Make sure you are able to repro it on the latest released version Search the existing issues. Refer to the FAQ. Refer to Differences between Windows PowerSh... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Perxenic-Acid |
| hostname | github.com |
| expected-hostname | github.com |
| None | b5b7bc7e41e0a604bbdb5035c7ed9620c2d28b9c8a18747182e2262a75abfd91 |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ff5022cc3aa767e6115451d9c322dd975506d40e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width