Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

user: TestGetAdditionalGroups/group_entry_with_out-of-range_gid fails on 32-bit architectures (GOARCH=386 / arm)

未关闭
#254 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
74/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go

调研方向

先查看 user/user_test.go 中 TestGetAdditionalGroups 附近的代码,以及 user/user.go 中 parseParts 附近的代码,然后运行 GOARCH=386 go test -v . -run "TestGetAdditionalGroups/group_entry_with_out-of-range_gid"。跟踪 GID 在 32 位和 64 位架构上的解析方式。完成标准是:超出范围的组条目在两种架构上都能可靠地返回预期错误,同时不会导致 User 或 Group ID 解析出现回归。

由索引模型根据 Issue 内容生成。

描述

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
  1. In user/user_test.go, the test defines groupContent with:

    toolarge:x:2147483648:
    

    where 2147483648 is math.MaxInt32 + 1.

  2. In user/user.go, parseParts() parses GID entries into *int via:

    case *int:
        *e, _ = strconv.Atoi(string(p))
    

    Conversion errors returned by strconv.Atoi are explicitly ignored (_).

  3. On 64-bit systems (int is int64), strconv.Atoi("2147483648") succeeds and sets *e = 2147483648. GetAdditionalGroups() then checks if g.Gid < minID || g.Gid > maxID (where maxID is 2147483647), correctly returning ErrRange.

  4. On 32-bit systems (int is int32), strconv.Atoi("2147483648") overflows int32 and returns strconv.ErrRange while setting *e = math.MaxInt32 (2147483647). Because the conversion error is discarded, g.Gid becomes 2147483647. Since 2147483647 <= 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:

  1. Parse IDs as int64 (e.g. strconv.ParseInt(string(p), 10, 64)) or validate strconv.ErrRange before truncating/converting to int, or
  2. Check whether the string value exceeds maxID (or check for strconv.ErrRange) when validating group/user entries so that 32-bit platforms reject out-of-range values consistently with 64-bit platforms.
主要语言
Go
星标
103
派生
64
平均合并
6 分钟
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

moby/sys 的其他 Issue

查看 moby/sys 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。