ArchiveReader: Preserve special permission bits during extraction - #839
Open
maksim-romanov wants to merge 1 commit into
Open
ArchiveReader: Preserve special permission bits during extraction#839maksim-romanov wants to merge 1 commit into
maksim-romanov wants to merge 1 commit into
Conversation
ArchiveReader.setFileAttributes was losing the sticky/set-user-ID/set-group-ID bits on every extracted regular file and directory, for two independent reasons: 1. apple#816 masked the applied fchmod mode to 0o777 to strip file-type bits picked up from the archived mode, but 0o777 also strips the sticky/set-user-ID/set-group-ID bits (0o7000) that extraction should keep. 2. setFileAttributes called fchmod before fchown. On Darwin, fchown clears set-user-ID/set-group-ID as a security measure, even when the new owner/group match the file's existing owner/group, so applying ownership after the mode silently drops those bits regardless of (1). Fix: apply ownership first, then fchmod with a 0o7777 mask (the full POSIX permission field, still excluding unrelated file-type bits). Added preserveSpecialPermissionBits() in ArchiveReaderTests.swift: extracts a 0o1777 directory and a 0o6755 regular file (owned by the current uid/gid so fchown succeeds without root) and asserts both survive extraction. Verified the test fails without the fix (reproducing the truncated values reported in the issues) and passes with it. swift test --filter ContainerizationArchiveTests (51 tests) and swift format lint --strict both clean. Closes apple#818 Closes apple#819
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.
ArchiveReader.setFileAttributes was losing the sticky/set-user-ID/set-group-ID
bits on every extracted regular file and directory, for two independent
reasons:
fchmodmode to0o777to strip file-type bitspicked up from the archived mode, but
0o777also strips thesticky/set-user-ID/set-group-ID bits (
0o7000) that extraction shouldkeep.
setFileAttributescalledfchmodbeforefchown. On Darwin,fchownclears set-user-ID/set-group-ID as a security measure, even when the new
owner/group match the file's existing owner/group, so applying ownership
after the mode silently drops those bits regardless of (1).
Fix: apply ownership first, then
fchmodwith a0o7777mask (the fullPOSIX permission field, still excluding unrelated file-type bits).
Added
preserveSpecialPermissionBits()inArchiveReaderTests.swift:extracts a
0o1777directory and a0o6755regular file (owned by thecurrent uid/gid so
fchownsucceeds without root) and asserts both surviveextraction. Verified the test fails without the fix (reproducing the
truncated values reported in the issues) and passes with it.
swift test --filter ContainerizationArchiveTests(51 tests) andswift format lint --strictboth clean.Closes #818
Closes #819