From a60cf2033cabf7a33ce54b3c93becd29efd8948b Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Tue, 18 Jan 2022 16:05:27 -0800 Subject: [PATCH] Fix off-by-one error in validation within `GetOffsetAtPosition` The incoming line number is 1-indexed (not 0-indexed), so while the lower limit was correctly set to 1, the upper limit was set to `FileLines.Count` which could be 0, but 0 lines implies an upper limit of 1 with this indexing. See `ScriptFile.GetLine` for the only other use of this 1-index range validation. --- .../Services/TextDocument/ScriptFile.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs b/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs index eeacab081..eb2569478 100644 --- a/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs +++ b/src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs @@ -411,7 +411,7 @@ public void ApplyChange(FileChange fileChange) /// The zero-based offset for the given file position. public int GetOffsetAtPosition(int lineNumber, int columnNumber) { - Validate.IsWithinRange("lineNumber", lineNumber, 1, this.FileLines.Count); + Validate.IsWithinRange("lineNumber", lineNumber, 1, this.FileLines.Count + 1); Validate.IsGreaterThan("columnNumber", columnNumber, 0); int offset = 0;