[Bug]: archive ownership changes clear set-ID permission bits
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- swift
- Domain
- operating-systems
Research direction
Start in ArchiveReader.setFileAttributes and inspect ArchiveReaderTests.swift around the preserveSpecialPermissionBits test. Run the provided swift test command to reproduce the failure, then verify extraction of a 06755 regular archive entry preserves its set-ID bits after ownership is applied.
Written by the indexing model from the issue text.
Description
I have done the following
- I have searched the existing issues
- I confirmed the ordering defect in
apple/containerizationmainat50f77222964ed3d01dcb53f803ea2d511656a9dc
Steps to reproduce
The syscall behaviour can be reproduced independently of the archive reader:
- Create and open a regular file.
- Call
fchmod(fd, 0o6755). - Call
fchown(fd, getuid(), getgid()). - Call
fstatand inspectst_mode & 0o7777.
On Darwin, step 3 clears the set-user-ID and set-group-ID bits, so the resulting mode is 0755.
The same ordering exists in ArchiveReader.setFileAttributes: it calls fchmod before fchown. Once the full permission mask from #818 is restored, this archive-specific regression demonstrates the defect:
-
Write a regular archive entry with mode
06755, ownergetuid(), and groupgetgid(). -
Extract it with
ArchiveReader. -
Read the extracted file's
.posixPermissions. -
Run:
swift test --disable-automatic-resolution -Xswiftc -warnings-as-errors --filter preserveSpecialPermissionBits
The test fails with:
Expectation failed: ((setIDPerms & permMask) -> 493) == (0o6755 -> 3565)
Set-ID permission bits should be preserved after ownership
Current behavior
ArchiveReader.setFileAttributes applies the archived mode and then changes ownership. Darwin's fchown clears set-user-ID and set-group-ID bits, including when ownership is set to the current UID and GID.
The issue is currently masked earlier by #818 because current main also truncates archive permissions to 0o777. It remains an independent defect in the stock main syscall ordering and becomes observable as soon as the full permission mask is restored.
Expected behavior
Archive extraction should set ownership first and apply the archived 0o7777 permission mode last, so the final extracted mode matches the archive entry.
Environment
- OS: macOS 26.5.1 (25F80)
- Xcode: 26.6 (17F113)
- Swift: Apple Swift 6.3.3
- Containerization source:
apple/containerizationmainat50f77222964ed3d01dcb53f803ea2d511656a9dc
Relevant log output
Test preserveSpecialPermissionBits() recorded an issue at ArchiveReaderTests.swift:484:9
Expectation failed: ((setIDPerms & permMask) -> 493) == (0o6755 -> 3565)
Set-ID permission bits should be preserved after ownership
Test run with 1 test in 1 suite failed with 1 issue.
Code of Conduct
- I agree to follow this project's Code of Conduct
- Dominant language
- Swift
- Stars
- 8.9k
- Forks
- 360
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 16
Contributor guide
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 apple/containerization
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apple/containerization#818 · 2 comments ·
-
LinuxContainer.create() leaks the VZ VM/XPC process when vm.start() throws — no do/catch around it Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
apple/containerization#804 ·
-
Difficulty 4/5 3-5 days Newbie friendliness 55/100
apple/containerization#921 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
apple/containerization#913 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 72/100
apple/containerization#912 ·
All issues in apple/containerization
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
type: docs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
googleapis/google-cloud-swift#971 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mozilla-mobile/firefox-ios#35743 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
manaflow-ai/cmux#13417 ·