From 4c59808788db73e78a3a425638fabb1496333882 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders <293473+sandersn@users.noreply.github.com> Date: Wed, 30 Oct 2024 11:42:05 -0700 Subject: [PATCH] Fix #60118 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. --- src/server/scriptVersionCache.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server/scriptVersionCache.ts b/src/server/scriptVersionCache.ts index 55a957928a1ae..1a0c8713db2fb 100644 --- a/src/server/scriptVersionCache.ts +++ b/src/server/scriptVersionCache.ts @@ -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; let childIndex = 0; let childCharCount = this.children[childIndex].charCount(); // find sub-tree containing start