fix: guard against invalid line in provideAltTextQuickFix (fixes #318227)#318228
Merged
vs-code-engineering[bot] merged 1 commit intoMay 25, 2026
Merged
Conversation
) 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: Copilot <223556219+Copilot@users.noreply.github.com>
dmitrivMS
approved these changes
May 25, 2026
roblourens
approved these changes
May 25, 2026
dileepyavan
pushed a commit
that referenced
this pull request
May 27, 2026
) (#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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🔧 Error Fix
Summary
The
provideAltTextQuickFixmethod in the Copilot Chat extension's code action provider callsdocument.lineAt(range.start.line)without validating that the line number is within the document's bounds. When the document is modified between when VS Code computes the code action range and when the provider executes,range.start.linecan exceeddocument.lineCount, causingTextDocument.lineAt()to throw "Illegal value forline".This error has been present across many extension versions (0.38.2 through 0.49.0) with ~10k+ total hits affecting ~4000+ users, indicating a persistent race condition in the code action lifecycle.
Fixes #318227
Recommended reviewer:
@AidanImmerCulprit Commit
Not identified — this is a long-standing bug present across all tracked extension versions (since at least 0.38.2). The
provideAltTextQuickFixmethod has always lacked bounds validation on the range parameter.Code Flow
sequenceDiagram participant VSCode as VS Code Editor participant QFP as QuickFixesProvider participant Doc as TextDocument VSCode->>QFP: provideCodeActions(doc, range, ...) Note over VSCode: Document modified after range computed QFP->>QFP: provideAltTextQuickFix(doc, range) QFP->>Doc: lineAt(range.start.line) Note over Doc: line >= lineCount Doc-->>QFP: throws "Illegal value for line"Affected Files
extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.tsprovideAltTextQuickFixcallslineAt()without bounds checkRepro Steps
lineAt()How the Fix Works
Chosen approach (
extensions/copilot/src/extension/inlineChat/vscode-node/inlineChatCodeActions.ts):Added a guard clause at the entry of
provideAltTextQuickFixthat validatesrange.start.lineis within[0, document.lineCount)before callingdocument.lineAt(). If the line is out of bounds, the method returnsundefinedearly (no alt-text quick fix offered for that invocation). This follows the principle of adding guard clauses upstream of the crash site to prevent the error path from being reached, rather than wrapping in try/catch which would hide the error from telemetry.The range is produced by VS Code's code action infrastructure and can become stale due to concurrent document edits — this is a known pattern where the consumer must validate framework-provided ranges.
Recommended Owner
@AidanImmer— owner of the Copilot Chat extension inline chat code actions based on the file path in the copilot extension area.