Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: checkptr false positive from (*[Big]T)(ptr)[:n:n] pattern #46938

Open
mdempsky opened this issue Jun 26, 2021 · 0 comments
Open

cmd/compile: checkptr false positive from (*[Big]T)(ptr)[:n:n] pattern #46938

mdempsky opened this issue Jun 26, 2021 · 0 comments
Assignees
Labels
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jun 26, 2021

checkptr has special case logic for recognizing the pattern (*[Big]T)(ptr)[:n:n]. In particular, instead of diagnosing whether (*[Big]T)(ptr) is an invalid conversion, it diagnoses (*[n]T)(ptr).

However, currently the checkptr instrumentation is inserted before the slice operation has validated n <= Big, so it's possible to have false positive throws in cases that should just be panics.

For example:

package main

import "unsafe"

func main() {
	s := make([]int64, 100)
	p := unsafe.Pointer(&s[0])
	n := 1000

	_ = (*[10]int64)(p)[:n:n] // throws; should just panic
}

This issue has existed since checkptr's inclusion in Go 1.14, and I'm not aware of any user reports about it. It's also easy to workaround.

Marking for Go 1.18.

@mdempsky mdempsky added this to the Go1.18 milestone Jun 26, 2021
@mdempsky mdempsky self-assigned this Jun 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant