fix(archive): restore permissions after ownership - #821
Open
stephenlclarke wants to merge 2 commits into
Open
Conversation
Archive extraction masked modes to ordinary rwx bits, stripping sticky, set-user-ID, and set-group-ID permissions. Preserve the full POSIX permission mask and add a sticky-directory regression.
Darwin clears set-user-ID and set-group-ID bits when fchown changes ownership. Apply ownership first, then restore the archived mode, and extend the archive regression to cover set-ID permissions.
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.
Summary
Apply archived permissions after ownership so Darwin does not clear set-user-ID and set-group-ID bits during extraction.
Motivation and Context
During testing of my
container-composeplugin, I found and fixed the following issue:ArchiveReader.setFileAttributescalledfchmodbeforefchown. On Darwin, changing ownership clears set-user-ID and set-group-ID bits, so the final extracted mode does not match the archive entry.Fixes #819.
Dependency and Merge Order
This PR targets the stock
apple/containerization:mainbranch and depends on #820, which fixes #818. Please merge #820 first.The head currently contains the signed #818 fix as its first prerequisite commit because both PRs target stock Apple
main. After the prerequisite merges, the branch can merge current Applemainso this PR's remaining diff is only the ownership/permission ordering change and set-ID regression.Reproduction
The syscall behaviour is directly reproducible:
fchmod(fd, 0o6755).fchown(fd, getuid(), getgid()).fstat(fd).st_mode & 0o7777.Darwin reports
0755.With the #818 mask fix present, the archive regression writes a regular entry with mode
06755, extracts it, and runs:swift test --disable-automatic-resolution -Xswiftc -warnings-as-errors --filter preserveSpecialPermissionBitsBefore reordering the calls, it failed with:
Changes
fchownbefore the finalfchmod.06755entry whose owner and group are explicitly restored.Validation
Validated on macOS 26.5.1 (25F80), Xcode 26.6 (17F113), and Swift 6.3.3.
0755instead of06755make fmt: passedmake check: passedswift test --enable-code-coverage --disable-automatic-resolution -Xswiftc -warnings-as-errors: 574 tests in 80 suites passedgit diff --check: passed6e32963617b3ed8f4b63432dbcf834f94807342band726e1ffdceada5cc62d32c8fc939aef30220e6ffare cryptographically signed and verifiedCompatibility and Risk
The change only alters the order of two existing file-descriptor operations. Ownership is still applied when both owner and group are present, and the archived mode becomes the final mode. There are no archive-format or public-API changes.
Related
Release Note Highlight
Archive extraction now preserves set-user-ID and set-group-ID bits when restoring file ownership.