Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.tar don't overwrite files on unpack #19081

Merged
merged 5 commits into from
Feb 26, 2024

Conversation

ianic
Copy link
Sponsor Contributor

@ianic ianic commented Feb 25, 2024

Don't silently overwrite files on tar unpack, return error instead.

In #18089 we are unpacking tar which has same file with different casing in name:

 $ tar tvf 18089.tar
     18089/
     18089/alacritty/
     18089/alacritty/darkermatrix.yml
     18089/alacritty/Darkermatrix.yml

On case insensitive file system (windows, macOS) that results in latter overwriting former silently. Further in the process that results in different package hashes between case sensitive and case insensitive operating systems.

From #18089:

The first step is to implement errors in the tar unpacking code when a tar file cannot be extracted correctly due to the file system being incompatible with the tar file.

That is what this commits do.
And some improved error reporting. That case on macOS now gives:

Fetch Packages [2/1] iterm2_themes... /Users/ianic/code/zig/issues/18089/build.zig.zon:19:20: error: unable to unpack tarball
            .url = "https://github.com/mbadolato/iTerm2-Color-Schemes/archive/aed2a8f0565a51913e8ddc1731f25bc71978a1e0.tar.gz",
                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
note: unable to create file 'alacritty/darkermatrix.yml': PathAlreadyExists
note: unable to create file 'alacritty/darkmatrix.yml': PathAlreadyExists
note: unable to create file 'alacritty/matrix.yml': PathAlreadyExists
note: unable to create file 'vscode/darkermatrix.json': PathAlreadyExists
note: unable to create file 'vscode/darkmatrix.json': PathAlreadyExists
note: unable to create file 'vscode/matrix.json': PathAlreadyExists

Another case where it is possible that we get file overwrite is when we unpack with strip_components > 0. That can result in files with same path/name, when leading component is stripped, to overwrite one another.

Fixes #18089

Fail with error if file already exists. File is not silently overwritten
but an error is raised.

Fixes: ziglang#18089
Like in issue ziglang#18089, this tar contains, same file name in two case
sensitive name version. Unpack should fail on case insensitive file
systems and succeed on case sensitive.

$ tar tvf 18089.tar
    18089/
    18089/alacritty/
    18089/alacritty/darkermatrix.yml
    18089/alacritty/Darkermatrix.yml
Report file name which failed to create in all cases.
Or other platform which don't support symlinks.
It was not returning error in all cases. Bug in refactoring.
@andrewrk andrewrk merged commit 81aa74e into ziglang:master Feb 26, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

package hash differs between operating systems due to file system case sensitivity
2 participants