apple / apple/containerization
[Bug]: archive extraction strips special permission bits
- Dominant language
- Swift
- Stars
- 8.9k
- Forks
- 359
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 13
Description
## I have done the following
- [x] I have searched the existing issues
- [x] I reproduced the issue against `apple/containerization` `main` at `50f77222964ed3d01dcb53f803ea2d511656a9dc`
## Steps to reproduce
1. Add an `ArchiveReaderTests` case that writes a directory entry with mode `01777`.
2. Extract the archive with `ArchiveReader`.
3. Read the extracted directory's `.posixPermissions`.
4. Run:
```sh
swift test --disable-automatic-resolution -Xswiftc -warnings-as-errors --filter preserveSpecialPermissionBits
```
On current `main`, the regression fails with:
```text
Expectation failed: ((perms & permMask) -> 511) == (0o1777 -> 1023)
Special permission bits should be preserved
```
The cause is `ArchiveReader.setFileAttributes`, which applies `entry.permissions & 0o777`. That mask strips the sticky, set-user-ID, and set-group-ID bits.
## Current behavior
Archive extraction preserves only ordinary owner/group/other read, write, and execute permissions. A `01777` directory is extracted as `0777`; set-user-ID and set-group-ID bits are also discarded.
This is a regression in `main` after #816 changed the extraction mask from the full mode to `0o777`.
## Expected behavior
Archive extraction should preserve the full POSIX permission field (`0o7777`) while continuing to exclude unrelated file-type bits.
## 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
```text
Test preserveSpecialPermissionBits() recorded an issue at ArchiveReaderTests.swift
Expectation failed: ((perms & permMask) -> 511) == (0o1777 -> 1023)
Special permission bits should be preserved
Test run with 1 test in 1 suite failed with 1 issue.
```
## Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Contributor guide
Research direction
Start in ArchiveReader.setFileAttributes and inspect the ArchiveReaderTests case named preserveSpecialPermissionBits. Run swift test --disable-automatic-resolution -Xswiftc -warnings-as-errors --filter preserveSpecialPermissionBits. Done means extraction preserves the full 0o7777 POSIX permission field, including sticky and set-ID bits, while excluding unrelated file-type bits.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 78/100