PSReadLine crashes with ArgumentOutOfRangeException on SetCursorPosition when quickly editing long input line (top=29, BufferHeight=29)

Ouverte Adaptée aux débutants
#5,195 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
68/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Calme
Stack technique
csharp
Domaine
cli

Piste de recherche

Reproduisez le plantage avec BufferHeight 29, puis suivez l’appel signalé à SetCursorPosition à travers MoveCursorToEnd pendant l’actualisation du tampon de la console. Vérifiez que la position supérieure du curseur reste comprise dans 0..BufferHeight-1 et confirmez qu’une édition rapide avec Backspace suivie d’une saisie ne ferme plus la session.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Needs-Triage :mag:
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
# PSReadLine crashes with ArgumentOutOfRangeException on rapid Backspace editing

## Environment
- PowerShell: 7.x (console)
- PSReadLine version: 2.4.5
- Terminal: Windows Console host, BufferHeight = 29

## Bug description
Typing commands and rapidly pressing Backspace caused PSReadLine to crash with
`ArgumentOutOfRangeException` thrown from `SetCursorPosition`:


Exception:
System.Management.Automation.PSArgumentOutOfRangeException:
Cannot process argument transformation on parameter 'top'.
Parameter name: 'top' cannot be greater than '29'


## Reproduction steps
1. Open a PowerShell console with a short window (BufferHeight ~29).
2. Type `vine update`, then `vine inventory`.
3. Press Backspace ~13 times quickly to erase, retype `vine inventory`, press Enter.
4. Press `r` — crash occurs.

## Root cause analysis
- The reported cursor line index is `29`, which is out of the valid range `0..28`
  when BufferHeight == 29.
- The crash happened during input-line redraw after a burst of Backspace keys,
  suggesting PSReadLine's cursor position calculation went out of bounds
  (off-by-one at the bottom edge of the buffer).

## Notes
- This is not caused by the command itself — any command can trigger it when
  the buffer is short and Backspace is pressed rapidly.
- Suggested fix: clamp the cursor `top` coordinate to `[0, BufferHeight-1]`
  before calling `SetCursorPosition`.

## Reporter context
Found while testing **Vine** (https://codeberg.org/Milktown/vine), a
text-instruction-based package manager for Windows. It has nothing to do with
the crash, just FYI — Vine is a neat open-source project worth a look. :)
Screenshot
Image
Environment data
PS Version: 7.6.3
PS HostName: ConsoleHost (Windows Terminal)
PSReadLine Version: 2.4.5
PSReadLine EditMode: Windows
OS: 10.0.19038.1 (WinBuild.160101.0800)
BufferWidth: 120
BufferHeight: 29
Steps to reproduce

Steps to reproduce

  1. Open PowerShell with a window sized so console BufferHeight is exactly 29 (e.g. 80 columns x 29 rows)
  2. Run: vine update
  3. Run: vine inventory
  4. Press Backspace 13 times rapidly (no text may remain, or partial)
  5. Retype: vine inventory
  6. Press Enter
  7. Type a single character, e.g. r — crash happens on redraw
Expected behavior

Expected behavior

  • Cursor line is clamped to valid range (0..BufferHeight-1); typing any character redraws the input line without errors
Actual behavior

Actual behavior

  • PSReadLine throws ArgumentOutOfRangeException: top parameter (29) is out of valid range 0..28
  • Stack: SetCursorPosition <- MoveCursorToEnd <- ... console buffer refresh; entire session crashes and closes
Langage dominant
C#
Étoiles
4.4k
Forks
341
Métriques de merge des PR
Aucune PR mergée en 30 j

Guide de contribution

Ouvrir le guide de contribution

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de PowerShell/PSReadLine

Toutes les issues de PowerShell/PSReadLine

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.