From f5a135b01fcbd0edbd9fb663803e22d1208fe314 Mon Sep 17 00:00:00 2001 From: "vs-code-engineering[bot]" <122617954+vs-code-engineering[bot]@users.noreply.github.com> Date: Mon, 25 May 2026 20:11:25 +0000 Subject: [PATCH] fix: guard against invalid line in provideAltTextQuickFix (fixes #318227) (#318228) The provideAltTextQuickFix method calls document.lineAt(range.start.line) without validating that the line number is within bounds. When the document is modified between when VS Code computes the range and when the code action provider executes, an out-of-bounds line number causes 'Illegal value for `line`' to be thrown. Add a bounds check before calling lineAt() so the method returns early instead of throwing. Co-authored-by: vs-code-engineering[bot] <122617954+vs-code-engineering[bot]@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../extension/inlineChat/vscode-node/inlineChatCodeActions.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts b/extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts index 6edcc1931b2..01669872748 100644 --- a/extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts +++ b/extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts @@ -136,6 +136,9 @@ export class QuickFixesProvider implements vscode.CodeActionProvider { } private provideAltTextQuickFix(document: vscode.TextDocument, range: vscode.Range): ImageCodeAction | undefined { + if (range.start.line < 0 || range.start.line >= document.lineCount) { + return; + } const currentLine = document.lineAt(range.start.line).text; const generateImagePath = extractImageAttributes(currentLine); const refineImagePath = extractImageAttributes(currentLine, true);