user: TestGetAdditionalGroups/group_entry_with_out-of-range_gid fails on 32-bit architectures (GOARCH=386 / arm)
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 74/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- go
- Domain
- operating-systems
Research direction
Start with user/user_test.go around TestGetAdditionalGroups and user/user.go around parseParts, then run GOARCH=386 go test -v . -run "TestGetAdditionalGroups/group_entry_with_out-of-range_gid". Trace how the GID is parsed on 32-bit and 64-bit architectures. Done means the out-of-range group entry reliably returns the expected error on both architectures without regressing User or Group ID parsing.
Written by the indexing model from the issue text.
Description
Description
When running tests in github.com/moby/sys/user on 32-bit architectures (e.g. GOARCH=386 or GOARCH=arm), TestGetAdditionalGroups/group_entry_with_out-of-range_gid fails:
=== RUN TestGetAdditionalGroups
=== RUN TestGetAdditionalGroups/group_entry_with_out-of-range_gid
user_test.go:651: Parse(struct { doc string; groups []string; expected []int; hasError bool }{doc:"group entry with out-of-range gid", groups:[]string{"toolarge"}, expected:[]int(nil), hasError:true}) expects error but has none
--- FAIL: TestGetAdditionalGroups (0.01s)
--- FAIL: TestGetAdditionalGroups/group_entry_with_out-of-range_gid (0.00s)
FAIL github.com/moby/sys/user 0.008s
Steps to Reproduce
cd user
GOARCH=386 go test -v . -run "TestGetAdditionalGroups/group_entry_with_out-of-range_gid"
Root Cause Analysis
-
In
user/user_test.go, the test definesgroupContentwith:toolarge:x:2147483648:where
2147483648ismath.MaxInt32 + 1. -
In
user/user.go,parseParts()parses GID entries into*intvia:case *int: *e, _ = strconv.Atoi(string(p))Conversion errors returned by
strconv.Atoiare explicitly ignored (_). -
On 64-bit systems (
intisint64),strconv.Atoi("2147483648")succeeds and sets*e = 2147483648.GetAdditionalGroups()then checksif g.Gid < minID || g.Gid > maxID(wheremaxIDis2147483647), correctly returningErrRange. -
On 32-bit systems (
intisint32),strconv.Atoi("2147483648")overflowsint32and returnsstrconv.ErrRangewhile setting*e = math.MaxInt32(2147483647). Because the conversion error is discarded,g.Gidbecomes2147483647. Since2147483647 <= maxID,GetAdditionalGroups()considers the GID valid, does not return an error, and the test fails.
Suggested Fix
parseParts (or Group.Gid / User.Uid / User.Gid parsing) should either:
- Parse IDs as
int64(e.g.strconv.ParseInt(string(p), 10, 64)) or validatestrconv.ErrRangebefore truncating/converting toint, or - Check whether the string value exceeds
maxID(or check forstrconv.ErrRange) when validating group/user entries so that 32-bit platforms reject out-of-range values consistently with 64-bit platforms.
- Dominant language
- Go
- Stars
- 100
- Forks
- 61
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 3
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from moby/sys
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
linonetwo/cpa-session-archive#25 ·
Maintainers usually reply within 1 day
-
area/testing kind/bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
agent-butler-finding bug
Difficulty 1/5 Under an hour Newbie friendliness 94/100
jordansmall/spindrift#4367 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day