Skip to content

ZipArchive creates broken zip files on Linux #27988

@MarcusWichelmann

Description

@MarcusWichelmann

When extracting a zip-file that was created using the ZipArchive class on Linux the resulting files have no permissions and cannot be opened.
Even changing the permissions using chmod has no effect.

I'm creating a simple .zip file using this code:

static void Main(string[] args)
{
    using (var fileStream = new FileStream("test.zip", FileMode.CreateNew))
    {
        using (var archive = new ZipArchive(fileStream, ZipArchiveMode.Create, leaveOpen: true))
        {
            ZipArchiveEntry entry = archive.CreateEntry("testfile.txt");
            using (var writer = new StreamWriter(entry.Open()))
            {
                writer.WriteLine("This is a test file.");
            }
        }
    }
}

and extract it using unzip:

$ ls -l
...
-rw-r--r-- 1 marcus marcus 150 Nov 24 16:17 test.zip
...
$ unzip test.zip 
Archive:  test.zip
  inflating: testfile.txt            
$ ls -l
...
---------- 1 marcus marcus  21 Nov 24 16:17 testfile.txt
-rw-r--r-- 1 marcus marcus 150 Nov 24 16:17 test.zip
...
$ cat testfile.txt 
cat: testfile.txt: Permission denied
$ chmod +r test.zip
$ ls -l
...
---------- 1 marcus marcus  21 Nov 24 16:17 testfile.txt
-rw-r--r-- 1 marcus marcus 150 Nov 24 16:17 test.zip
...

Using graphical programs to extract it doesn't work either.

$ zipinfo test.zip 
Archive:  test.zip
Zip file size: 150 bytes, number of entries: 1
?---------  2.0 unx       21 b- defN 18-Nov-24 16:33 testfile.txt
1 file, 21 bytes uncompressed, 28 bytes compressed:  -33.3%
$ dotnet --version
2.1.403

Here is the resulting zip-file for further analysis:
test.zip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions