Skip to content

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

Merged
andrewrk merged 5 commits intoziglang:masterfrom
ianic:tar_case_sensitive
Feb 26, 2024
Merged

std.tar don't overwrite files on unpack#19081
andrewrk merged 5 commits intoziglang:masterfrom
ianic:tar_case_sensitive

Conversation

@ianic
Copy link
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
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