Skip to content

PSReadLine crashes with ArgumentOutOfRangeException (SetCursorPosition top = -1) when recalling history after terminal output scrolls #5192

Description

@Silent-xiaomiao

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

System.ArgumentOutOfRangeException: 该值必须大于或等于零,且必须小于控制台缓冲区在该维度的大小。
参数名: top
实际值是 -1。
   在 System.Console.SetCursorPosition(Int32 left, Int32 top)
   在 Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   在 Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   在 Microsoft.PowerShell.PSConsoleReadLine.HistoryRecall(Int32 direction)
   在 Microsoft.PowerShell.PSConsoleReadLine.PreviousHistory(Nullable`1 key, Object arg)
   在 Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   在 Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   在 Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

Screenshot

no

Environment data

PS Version: 5.1.19041.1645
PS HostName: ConsoleHost
PSReadLine Version: 2.0.0-beta2
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 120
BufferHeight: 3000

Steps to reproduce

  1. 运行一条输出超过一屏的命令(如 Get-ChildItem C:\Windows -Recurse | Select-Object -First 5000),让缓冲区滚动。
  2. 可选:执行 cls 或调整终端窗口大小。
  3. 连续按 UpArrow 翻历史。
  4. PSReadLine 崩溃,输入中断,直到新开一行才恢复。

Expected behavior

翻历史时正常渲染,不抛异常。

Actual behavior

按 UpArrow 触发 HistoryRecall → ReallyRender 里 SetCursorPosition(top=-1) 抛 ArgumentOutOfRangeException,PSReadLine 崩溃。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions