Skip to content

math/rand: read can panic #71402

@tcsato995

Description

@tcsato995

go version go1.23.2 linux/amd64

Happened only once, so not sure how to reproduce it, however calling rand.read with a rngSource caused a panic, see stack trace below. It was called in a 3rd party library, but if that matters the buffer slice given to the read method has a hardcoded size of 56, and rand instance was created with rand.NewSource(time.Now().UnixNano())

panic: runtime error: index out of range [-1]

goroutine 138 [running]:
math/rand.(*rngSource).Uint64(...)
	/usr/local/go/src/math/rand/rng.go:249
math/rand.(*rngSource).Int63(...)
	/usr/local/go/src/math/rand/rng.go:234
math/rand.read({0xc000117680, 0x38, 0xc000df1888?}, {0x1eb34e0?, 0xc000375500?}, 0xc000364a70, 0xc000364a78)
	/usr/local/go/src/math/rand/rand.go:285 +0x185
math/rand.(*Rand).Read(0xc000bcf0e0?, {0xc000117680?, 0x7f1d0cc6c108?, 0x30?})
	/usr/local/go/src/math/rand/rand.go:275 +0x65
.
.
.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.FrozenDueToAgeWaitingForInfoIssue is not actionable because of missing required information, which needs to be provided.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions