PowerShell autocomplete crashes if larger than current screen #9944

Closed
opened 2026-01-31 02:08:05 +00:00 by claunia · 3 comments
Owner

Originally created by @cjoprey on GitHub (Jul 31, 2020).

Environment

Windows build number: Microsoft Windows NT 10.0.18363.0
Windows Terminal version (if applicable): 1.2.2022.0
PowerShell version: 5.1.18362.752

Steps to reproduce

  • Open a PowerShell window in Windows Terminal
  • Run the following: cd \Windows
  • Enter dir<space>
  • Hit ctrl + space to trigger the autocomplete. It should say something like "Display all 136 possibilities? (y or n) _"
  • Hit "y"

Expected behavior

In a normal PowerShell window, it now lists all entries. Below is a snip from PowerShell.exe:

C:\Windows> dir
addins
appcompat
apppatch
< ...snipped all the other entries... >
WinSxS
wlansvc
WMSysPr9.prx
write.exe
C:\Windows> dir    

Actual behavior

In Windows terminal, with the same console size (checked with $Host.UI.RawUI.WindowSize), it causes PowerShell to crash with an out of bounds error, and I believe it it because there is no forward buffer like there is in PowerShell.exe:

Oops, something went wrong.  Please report this bug with the details below.
Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new
-----------------------------------------------------------------------
Last 200 Keys:
 g i t Space b r a n c h Space Tab Ctrl+Space Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Space Backspace Space b r n a h c Space Backspace Backspace Backspace Backspace Backspace a n c h Space Ctrl+Space Escape Escape Escape c l s Enter
 c d Space . . Enter
 c l s Enter
 $ H o s t . U I . R a w U I . W i n d o w S i z e Enter
 c d Space \ w i n d w Tab Backspace Tab Enter
 c l s Enter
 UpArrow UpArrow UpArrow Enter
 d i r Space Ctrl+Space y Escape c l s Enter
 UpArrow UpArrow Enter
 [ E n v i r o n m e n t ] : : O S V e r s i o n Enter
 d i r Space Ctrl+Space Escape Backspace Backspace Backspace Backspace c l s Enter
 UpArrow UpArrow UpArrow UpArrow DownArrow Enter
 $ p s v e r Tab Enter
 d i r Space Ctrl+Space y

Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -99.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.Menu.EnsureMenuAndInputIsVisible(IConsole console, Int32 tooltipLineCount)
   at Microsoft.PowerShell.PSConsoleReadLine.Menu.DrawMenu(Menu previousMenu)
   at Microsoft.PowerShell.PSConsoleReadLine.PossibleCompletionsImpl(CommandCompletion completions, Boolean menuSelect)
   at Microsoft.PowerShell.PSConsoleReadLine.CompleteImpl(Boolean menuSelect)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------
C:\Windows> dir     
Originally created by @cjoprey on GitHub (Jul 31, 2020). # Environment ```none Windows build number: Microsoft Windows NT 10.0.18363.0 Windows Terminal version (if applicable): 1.2.2022.0 PowerShell version: 5.1.18362.752 ``` # Steps to reproduce - Open a PowerShell window in Windows Terminal - Run the following: `cd \Windows` - Enter `dir<space>` - Hit ctrl + space to trigger the autocomplete. It should say something like "Display all 136 possibilities? (y or n) _" - Hit "y" # Expected behavior In a normal PowerShell window, it now lists all entries. Below is a snip from PowerShell.exe: ``` C:\Windows> dir addins appcompat apppatch < ...snipped all the other entries... > WinSxS wlansvc WMSysPr9.prx write.exe C:\Windows> dir ``` # Actual behavior In Windows terminal, with the same console size (checked with $Host.UI.RawUI.WindowSize), it causes PowerShell to crash with an out of bounds error, and I believe it it because there is no forward buffer like there is in PowerShell.exe: ``` Oops, something went wrong. Please report this bug with the details below. Report on GitHub: https://github.com/lzybkr/PSReadLine/issues/new ----------------------------------------------------------------------- Last 200 Keys: g i t Space b r a n c h Space Tab Ctrl+Space Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Backspace Space Backspace Space b r n a h c Space Backspace Backspace Backspace Backspace Backspace a n c h Space Ctrl+Space Escape Escape Escape c l s Enter c d Space . . Enter c l s Enter $ H o s t . U I . R a w U I . W i n d o w S i z e Enter c d Space \ w i n d w Tab Backspace Tab Enter c l s Enter UpArrow UpArrow UpArrow Enter d i r Space Ctrl+Space y Escape c l s Enter UpArrow UpArrow Enter [ E n v i r o n m e n t ] : : O S V e r s i o n Enter d i r Space Ctrl+Space Escape Backspace Backspace Backspace Backspace c l s Enter UpArrow UpArrow UpArrow UpArrow DownArrow Enter $ p s v e r Tab Enter d i r Space Ctrl+Space y Exception: System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension. Parameter name: top Actual value was -99. at System.Console.SetCursorPosition(Int32 left, Int32 top) at Microsoft.PowerShell.PSConsoleReadLine.Menu.EnsureMenuAndInputIsVisible(IConsole console, Int32 tooltipLineCount) at Microsoft.PowerShell.PSConsoleReadLine.Menu.DrawMenu(Menu previousMenu) at Microsoft.PowerShell.PSConsoleReadLine.PossibleCompletionsImpl(CommandCompletion completions, Boolean menuSelect) at Microsoft.PowerShell.PSConsoleReadLine.CompleteImpl(Boolean menuSelect) at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg) at Microsoft.PowerShell.PSConsoleReadLine.InputLoop() at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics) ----------------------------------------------------------------------- C:\Windows> dir ```
claunia added the Resolution-ExternalNeeds-Tag-Fix labels 2026-01-31 02:08:05 +00:00
Author
Owner

@DHowett commented on GitHub (Jul 31, 2020):

This is going to have the same root cause as /dup https://github.com/PowerShell/PSReadLine/issues/1417

PSReadline doesn't act right when the buffer is the same size as the screen, and the fix needs to be done in their repo. 😄

@DHowett commented on GitHub (Jul 31, 2020): This is going to have the same root cause as /dup https://github.com/PowerShell/PSReadLine/issues/1417 PSReadline doesn't act right when the buffer is the same size as the screen, and the fix needs to be done in their repo. :smile:
Author
Owner

@ghost commented on GitHub (Jul 31, 2020):

Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!

@ghost commented on GitHub (Jul 31, 2020): Hi! We've identified this issue as a duplicate of one that exists on somebody else's Issue Tracker. Please make sure you subscribe to the referenced external issue for future updates. Thanks for your report!
Author
Owner

@DHowett commented on GitHub (Jul 31, 2020):

(I know they sound different, but the root cause is that they mishandle the buffer when it cannot grow.)

@DHowett commented on GitHub (Jul 31, 2020): (I know they sound different, but the root cause is that they mishandle the buffer when it cannot grow.)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#9944