Skip to content

Commit 1335f05

Browse files
committed
gopls/internal/util/frob: Decode: improve panic on empty
Also, add justification for fall through. Updates golang/go#71244 Change-Id: I781d015a9d4659815588e95dea92eb350388b925 Reviewed-on: https://go-review.googlesource.com/c/tools/+/642435 Reviewed-by: Robert Findley <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent 0b95e04 commit 1335f05

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

gopls/internal/cache/check.go

+1
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,7 @@ func (s *Snapshot) typerefData(ctx context.Context, id PackageID, imports map[Im
12901290
return data, nil
12911291
} else if err != filecache.ErrNotFound {
12921292
bug.Reportf("internal error reading typerefs data: %v", err)
1293+
// Unexpected error: treat as cache miss, and fall through.
12931294
}
12941295

12951296
pgfs, err := s.view.parseCache.parseFiles(ctx, token.NewFileSet(), parsego.Full&^parser.ParseComments, true, cgfs...)

gopls/internal/util/frob/frob.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ func (fr *frob) Decode(data []byte, ptr any) {
244244
panic(fmt.Sprintf("got %v, want %v", rv.Type(), fr.t))
245245
}
246246
rd := &reader{data}
247-
if string(rd.bytes(4)) != magic {
248-
panic("not a frob-encoded message")
247+
if len(data) < len(magic) || string(rd.bytes(len(magic))) != magic {
248+
panic("not a frob-encoded message") // (likely an empty message)
249249
}
250250
fr.decode(rd, rv)
251251
if len(rd.data) > 0 {

0 commit comments

Comments
 (0)