Skip to content

fix: use io.ReadFull(rand.Reader, b) in generateRandomBytes - #209

Open
aoright wants to merge 1 commit into
gorilla:mainfrom
aoright:fix/use-io-readfull-for-rand-reader
Open

aoright wants to merge 1 commit into
gorilla:mainfrom
aoright:fix/use-io-readfull-for-rand-reader

Conversation

@aoright

@aoright aoright commented Aug 19, 2026

Copy link
Copy Markdown

Problem

In Go 1.24+, crypto/rand.Read was updated to read from the OS entropy source directly rather than delegating through rand.Reader. In unit tests where rand.Reader is substituted with custom readers (e.g. shortReader in TestGenerateRandomBytes), calling rand.Read(b) causes a fatal runtime panic (crypto/rand: failed to read random data: unexpected EOF, see https://go.dev/issue/66821).

Solution

  • Change rand.Read(b) in generateRandomBytes to io.ReadFull(rand.Reader, b) so that it respects rand.Reader and gracefully returns io.ErrUnexpectedEOF on short reads without crashing.

Signed-off-by: aoright <102943475+aoright@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant