Repository navigation
llb: parse chown IDs across the whole uid_t range - #7346
Merged
Merged
Conversation
WithUser() split a "user:group" string with parseUID(), which used strconv.ParseInt(.., 10, 32). Any value in 2^31..2^32-1 is a valid uid_t or gid_t, but ParseInt rejects it, so the numeric ID fell into the name branch and the daemon tried to resolve "2147483648" in /etc/passwd. When that lookup found nothing the copy silently stayed owned by root, so COPY --chown=2147483648 produced no error and no requested ownership. Parse the same way the daemon side already does in executor/oci: as an unsigned 32-bit value. A sign prefix is no longer accepted as an ID, which also removes the wrap-around that turned "-1" into 4294967295. Refs moby#7292 Signed-off-by: ump45nose <ump45nose@users.noreply.github.com>
tonistiigi
approved these changes
Nov 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this PR does / why we need it
llb.WithUser()splits auser:groupstring and parses each part withparseUID(), which usedstrconv.ParseInt(str, 10, 32).uid_t/gid_tspan0..2^32-1, butParseIntrejects everything from2^31up, so a perfectlyvalid numeric ID fell into the name branch and was sent to the daemon as a
UserOpt_ByName.readUser()treats "not found in /etc/passwd" as "leave italone", so
COPY --chown=2147483648 file.txt /asucceeded and silently leftthe file owned by root.
The daemon side already parses the same syntax with
strconv.ParseUint(str, 10, 32)(parseUIDinexecutor/oci/user.go), so theclient was the odd one out; this aligns the two.
One side effect: a sign prefix is no longer accepted as an ID. Previously
WithUser("-1")parsed as-1andmarshal()narrowed it touint32(-1), i.e.4294967295. Such a value now stays a name lookup, like anyother non-numeric string.
Which issue(s) this PR fixes / relates to
Refs #7292 — this covers only the client-side numeric ID parsing. The separate
question of
readUser()silently ignoring a name that cannot be resolved isnot addressed here.
Testing
go test -p 1 -count=1 ./client/llb/...-> ok (llb, llbbuild, llbtest).client/llb/fileop_test.go:TestFileOwnerWithUIDAndGIDAboveInt32andTestFileOwnerWithNegativeUID.Both fail on the pre-change tree (the
*pb.UserOpt_ByIDassertion panicsbecause the value arrives as
UserOpt_ByName) and pass with the fix.go test -p 1 -count=1 ./frontend/dockerfile/...->dockerfile2llb,instructions,parser,shell,dfgitutil,versionall ok. Thefrontend/dockerfileTestIntegrationsuite fails with "failed to lookupregistry binary" both before and after this change on this host (it needs a
container worker/registry), so it was not exercised here.
gofmt -l client/llb/andgo vet ./client/llb/clean.Breaking change?
No. Values that already parsed keep their meaning; values that previously
produced a silent root ownership now produce the requested ID.
Prepared with AI assistance; the diff and the test results above were reviewed and run by me.