[tools] gopls: two mitigations for "surplus bytes" crash

0 views
Skip to first unread message

Alan Donovan (Gerrit)

unread,
Jun 29, 2026, 4:52:50 PM (2 days ago) Jun 29
to goph...@pubsubhelper.golang.org, golang-...@googlegroups.com, Alex Putman, golang...@luci-project-accounts.iam.gserviceaccount.com, golang-co...@googlegroups.com

Alan Donovan submitted the change

Change information

Commit message:
gopls: two mitigations for "surplus bytes" crash

In go.dev/issue/80166 a "surplus bytes" error was observed during
frob decoding. This "cannot happen" because Encode and Decode
are strictly dual, and the design of the cache means that
we do not attempt to decode a file with the wrong checksum,
so hardware faults or file system corruption is eliminated as
a cause.

This CL adds two defensive measures to try to resolve the mystery:
1) frob encoding asserts that the number of map iterations
matches the length, in case the map was somehow concurrently
mutated. (Better to crash than write a corrupt cache entry.)
2) during filecache creation, we record the complete SHA digest
of th executable, and check it on subsequent startups that
hit an existing directory, in case we have a case of the
birthday paradox (though with 32 bits this is exceeedingly
unlikely).

Also, simplify using sync.OnceValues.

For golang/go#80166
Change-Id: I26625a806b10087070a4f4b67f78bd0156b48357
Auto-Submit: Alan Donovan <adon...@google.com>
Reviewed-by: Alex Putman <apu...@golang.org>
Files:
  • M gopls/internal/filecache/filecache.go
  • M gopls/internal/util/frob/frob.go
Change size: M
Delta: 2 files changed, 56 insertions(+), 48 deletions(-)
Branch: refs/heads/master
Submit Requirements:
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: tools
Gerrit-Branch: master
Gerrit-Change-Id: I26625a806b10087070a4f4b67f78bd0156b48357
Gerrit-Change-Number: 795440
Gerrit-PatchSet: 3
Gerrit-Owner: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alan Donovan <adon...@google.com>
Gerrit-Reviewer: Alex Putman <apu...@golang.org>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages