Skip to content

Commit 96a7e9e

Browse files
Fix off-by-one error in validation within GetOffsetAtPosition (#1669)
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.
1 parent 3ea4eb9 commit 96a7e9e

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/PowerShellEditorServices/Services/TextDocument/ScriptFile.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ public void ApplyChange(FileChange fileChange)
411411
/// <returns>The zero-based offset for the given file position.</returns>
412412
public int GetOffsetAtPosition(int lineNumber, int columnNumber)
413413
{
414-
Validate.IsWithinRange("lineNumber", lineNumber, 1, this.FileLines.Count);
414+
Validate.IsWithinRange("lineNumber", lineNumber, 1, this.FileLines.Count + 1);
415415
Validate.IsGreaterThan("columnNumber", columnNumber, 0);
416416

417417
int offset = 0;

0 commit comments

Comments
 (0)