Fix silent archive-extraction overwrites from APFS path collisions on macOS#30245
Open
tomasilluminati wants to merge 1 commit into
Open
Fix silent archive-extraction overwrites from APFS path collisions on macOS#30245tomasilluminati wants to merge 1 commit into
tomasilluminati wants to merge 1 commit into
Conversation
2 tasks
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.
Description
On macOS the archive decompressors compare entry names as raw bytes, but APFS folds names through Unicode normalization (NFC/NFD) and, on case-insensitive volumes, case folding. Two byte-distinct entries can therefore hit the same inode, and the second silently overwrites the first: for example
pkg/ss_output.txtandpkg/ß_output.txtunderstrip_prefix "pkg", orSECRET.envnext tosecret.env. Both still land inside the destination, so this is a name collision (CWE-706, CWE-176), not a directory escape.I add
HostPathCollisionChecker. Per extraction it records each written target in the host's equivalence form and throws if a byte-distinct entry resolves to one already written. It is wired intoCompressedTarFunction,ZipDecompressor,SevenZDecompressorandArFunction; identical bytes keep the current last-writer-wins behavior. Folding is canonical NFC plus case folding, not NFKC, which over-folds compatibility forms that APFS keeps distinct. Off macOS it is a no-op, so Linux and Windows are unchanged.-Dbazel.darwin.case_sensitive=truedrops the case-fold step for case-sensitive volumes.Motivation
A silent overwrite during extraction is a data integrity bug: an archive can carry two files a Linux build sees as separate, and on a Mac one clobbers the other with no warning. This turns the collision into a hard error instead.
Build API Changes
No
Checklist
Release Notes
RELNOTES: On macOS, archive extraction now errors when two byte-distinct entries resolve to the same path under APFS normalization or case folding, instead of silently overwriting.