From 970de8e4330b5e1226800c43bc5659f29b78f739 Mon Sep 17 00:00:00 2001 From: jftkcs <120062444+jftkcs@users.noreply.github.com> Date: Mon, 16 Jun 2025 21:45:53 -0700 Subject: [PATCH 1/2] Add Y bounds check to InvokePrompt (#4790) --- PSReadLine/ReadLine.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index 677025aa..dabb0e86 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -1035,16 +1035,24 @@ public static void DigitArgument(ConsoleKeyInfo? key = null, object arg = null) public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) { var console = _singleton._console; - console.CursorVisible = false; if (arg is int newY) { + if (newY < 0 || newY >= console.BufferHeight) + throw new ArgumentOutOfRangeException(nameof(arg)); + + console.CursorVisible = false; console.SetCursorPosition(0, newY); } else { newY = _singleton._initialY - _singleton._options.ExtraPromptLineCount; + // Silently return if user has implicitly requested an impossible prompt invocation. + if (newY < 0) + return; + + console.CursorVisible = false; console.SetCursorPosition(0, newY); // We need to rewrite the prompt, so blank out everything from a previous prompt invocation From c3a335ac240f614d2318b945327ce7a8e34c67a5 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Wed, 9 Jul 2025 16:03:34 -0700 Subject: [PATCH 2/2] Minor update on the coding style --- PSReadLine/ReadLine.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PSReadLine/ReadLine.cs b/PSReadLine/ReadLine.cs index dabb0e86..d810a328 100644 --- a/PSReadLine/ReadLine.cs +++ b/PSReadLine/ReadLine.cs @@ -1039,8 +1039,10 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) if (arg is int newY) { if (newY < 0 || newY >= console.BufferHeight) + { throw new ArgumentOutOfRangeException(nameof(arg)); - + } + console.CursorVisible = false; console.SetCursorPosition(0, newY); } @@ -1050,7 +1052,9 @@ public static void InvokePrompt(ConsoleKeyInfo? key = null, object arg = null) // Silently return if user has implicitly requested an impossible prompt invocation. if (newY < 0) + { return; + } console.CursorVisible = false; console.SetCursorPosition(0, newY);