Skip to content

sync/atomic: atomic.Pointer[T] can be misused with type conversions. #56603

Closed
@mateusz834

Description

@mateusz834
package main

import (
	"math"
	"sync/atomic"
)

type small struct {
	small [64]byte
}

type big struct {
	big [math.MaxUint16 * 10]byte
}

func main() {
	a := atomic.Pointer[small]{}
	a.Store(&small{})

	b := atomic.Pointer[big](a) // type conversion
	big := b.Load()

	for i := range big.big {
		big.big[i] = 1
	}
}

This sample (on my system) produces a segfault:

[mateusz@arch aa ]$ go run main.go
signal: segmentation fault (core dumped)

So we basically done a unsafe type conversion without using the unsafe package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions