Skip to content

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

Closed

Description

@mdempsky

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.

Activity

  1. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Jun 26, 2021
  2. added this to the Go1.18 milestone on Jun 26, 2021
  3. self-assigned this
    on Jun 26, 2021
  4. gopherbot commented on Aug 21, 2021

    @gopherbot
    Contributor

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

  5. locked and limited conversation to collaborators on Jun 23, 2023
  6. added a commit that references this issue on Apr 29, 2024
    de1c934
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    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