Skip to content

cmd/compile: expand checkptr to find conversions of smaller types into bigger #34959

Closed
@ainar-g

Description

@ainar-g

Per discussion in golang-dev.

The checkptr dynamic analyser doesn't find bad type conversions between types where the destination type is greater than the source type. E. g.:

var i32sink int32

type t1 struct { a, b int32 }

type t2 struct { a, b, c, d int32 }

func main() {
	for i := 0; i < 1000; i++ {
		var badt2 = *(*t2)(unsafe.Pointer(&t1{}))
		i32sink = badt2.d
	}
}

Playground link: https://play.golang.org/p/32lWMkFPvm5.

According to @mdempsky:

Detecting that is not currently supported, but I think there may at least be some cases where we can detect it. (…)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions