[Bug]: archive ownership changes clear set-ID permission bits

Open Beginner friendly
#819 1 comment 1 reaction 0 assignees View on GitHub

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

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/containerization main at 50f77222964ed3d01dcb53f803ea2d511656a9dc

Steps to reproduce

The syscall behaviour can be reproduced independently of the archive reader:

  1. Create and open a regular file.
  2. Call fchmod(fd, 0o6755).
  3. Call fchown(fd, getuid(), getgid()).
  4. Call fstat and inspect st_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:

  1. Write a regular archive entry with mode 06755, owner getuid(), and group getgid().

  2. Extract it with ArchiveReader.

  3. Read the extracted file's .posixPermissions.

  4. 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/containerization main at 50f77222964ed3d01dcb53f803ea2d511656a9dc

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from apple/containerization

All issues in apple/containerization

Similar issues

More Swift issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.