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

Closed
mdempsky opened this issue Jun 26, 2021 · 1 comment
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@mdempsky
Copy link
Member

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 the NeedsFix The path to resolution is known, but the work has not been done. label Jun 26, 2021
@mdempsky mdempsky added this to the Go1.18 milestone Jun 26, 2021
@mdempsky mdempsky self-assigned this Jun 26, 2021
@gopherbot
Copy link

Change https://golang.org/cl/343972 mentions this issue: cmd/compile: fix checkptr false positive for (*[Big]T)(ptr)[:n:n] pattern

@golang golang locked and limited conversation to collaborators Jun 23, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

2 participants