Skip to content

internal/coverage/decodemeta: mishandled function literal flag in covdata read #57942

Closed
@thanm

Description

@thanm

What version of Go are you using (go version)?

$ go version
go version devel go1.21-46d19b3ac9 Thu Jan 19 10:19:48 2023 -0500 linux/amd64

Does this issue reproduce with the latest release?

Only on tip / go 1.20

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

Build this program with "-cover" and run to collect coverage profile.

https://go.dev/play/p/Gs7UJrWz86r?v=gotip

E.g.

$ go build -o prog.exe -cover prog.go
$ mkdir /tmp/covdata
$ GOCOVERDIR=/tmp/covdata ./prog.exe
$ go tool covdata func -i=tmp/covdata
...

What did you expect to see?

Coverage profile includes "main".

What did you see instead?

Coverage profile is missing "main":

$ go tool covdata func -i=/tmp/covdata
/tmp/prog.go:5:	*Atyp.Set	100.0%
/tmp/prog.go:9:	Atyp.Get	100.0%
total                        (statements)	100.0%
$

What's happening here is that there is a coding error in the handling of the function literal flag in the meta-data decoder., this code here:

	lit := d.r.ReadULEB128()
	if lit != 0 {
		f.Lit = true
	}

is written incorrectly. The update to f.Lit should be unconditional (since we can't make any assumptions about the state of the FuncDesc passed in). If clients always pass in a zero FuncDesc everything will appear to work ok, but if not, the state of the "Lit" field will be whatever it was set to on the last go around.

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions