Skip to content

Fix a crash in an anonymous buffer that copilot is writing to. #60377

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2024

Conversation

sandersn
Copy link
Member

Fix #60118

LineNode.walk reads the first element out of LineNode.children without checking that there are any elements to read. Of course, it's supposed to be called only on nodes that have children.

Why no tests?

Fix a crash in an unbacked buffer that copilot is writing to.

LineNode.walk reads the first element out of LineNode.children without
checking that there are any elements to read. Of course, it's supposed
to be called only on nodes that have children.

Why no tests?
-------------

- This failure is flaky -- I never managed to reproduce it.
- scriptVersionCache is barely maintained. The last two fixes in this
  particular code are 3.5 and 6.5 years ago.
- #21924 has no tests to fix an assert
- af47ddbc3b0c6421c38b18e56f8da88434a473c8d has an exasperated comment
  about the difficulty of learning invariants and an apology for an
  only-possibly-relevant test.
- So, I didn't think the effort of a complete fix was worthwhile in a case where a
  small, local fix will stop the crashes.
@typescript-bot typescript-bot added Author: Team For Milestone Bug PRs that fix a bug with a specific milestone labels Oct 30, 2024
@sandersn sandersn changed the title Fix a crash in an unbacked buffer that copilot is writing to. Fix a crash in an anonymous buffer that copilot is writing to. Oct 30, 2024
@@ -632,6 +632,7 @@ export class LineNode implements LineCollection {

walk(rangeStart: number, rangeLength: number, walkFns: LineIndexWalker): void {
// assume (rangeStart < this.totalChars) && (rangeLength <= this.totalChars)
if (this.children.length === 0) return;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this.children always defined?

Copy link
Member Author

@sandersn sandersn Oct 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the type is LineCollection[] and the constructor defaults it to [] if it's not provided.

Edit: in fact, there are no explicit assignments to it; just the implicit private readonly children: LineCollection[] = [] in the constructor.

@sandersn sandersn merged commit da15ef2 into main Oct 30, 2024
32 checks passed
@sandersn sandersn deleted the fix-copilot-streaming-crash branch October 30, 2024 22:36
@sandersn sandersn removed this from PR Backlog Apr 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Author: Team For Milestone Bug PRs that fix a bug with a specific milestone
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Crash for copilot code block
3 participants