Skip to content

os/user: GroupIds fails when a member of more than 256 groups on macOS #78337

@Bo98

Description

@Bo98

Go version

go version go1.26.1 darwin/arm64

Output of go env in your module/workspace:

AR='ar'
CC='cc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='c++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/Users/bo/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/bo/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/q9/nmz5wgw924g_6p764q646d200000gn/T/go-build3751182643=/tmp/go-build -gno-record-gcc-switches -fno-common'
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/Users/bo/test-repo/go.mod'
GOMODCACHE='/Users/bo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/bo/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.26.1/libexec'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/bo/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.26.1/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.26.1'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

Calling GroupIds when the user is a member of more than 256 groups fails on macOS.

This was originally reported at #21067 and fixed in f100e0c but regressed again in 185766d. The Darwin-specific groupRetry code was (presumably) erroneously removed.

Here's a rough test script I used to reproduce the issue in CI. I've minimised it a bit but should hopefully still reproduce the issue:

package main

import "os/user"

func main() {
	usr, err := user.Current()
	if err != nil {
		panic(err)
	}

	_, err = usr.GroupIds()
	println("GroupIds success =", err == nil)
}
#!/bin/bash
set -euo pipefail

GROUP_COUNT=300

for i in $(seq 1 "${GROUP_COUNT}"); do
  sudo dseditgroup -o create "dummygroup${i}"
  sudo dseditgroup -o edit -a "${USER}" -t user "dummygroup${i}"
done

cleanup() {
  for i in $(seq 1 "${GROUP_COUNT}"); do
    sudo dseditgroup -o delete -q "dummygroup${i}" || true
  done
}
trap cleanup EXIT

go run main.go

What did you see happen?

GroupIds success = false

What did you expect to see?

GroupIds success = true

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Darwin

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions