Skip to content

Password-protected ZIP archives cannot be extracted if they contain an empty file #132213

Description

@pawlos

Description

A password-protected archive containing an empty file cannot be read back by the code that wrote it.

Reproduction Steps

using System.IO.Compression;

const string Password = "hunter2";

Directory.CreateDirectory("src");
File.WriteAllText("src/readme.txt", "hello world");
File.WriteAllText("src/.gitkeep", "");              // ordinary empty file

ZipFile.CreateFromDirectory("src", "out.zip", new ZipFileCreationOptions
{
    Password = Password.AsMemory(),
    EncryptionMethod = ZipEncryptionMethod.Aes256,
});

ZipFile.ExtractToDirectory("out.zip", "dst", new ZipExtractionOptions
{
    Password = Password.AsMemory(),
});   // throws InvalidDataException

Expected behavior

An archive written by System.IO.Compression can be read back by System.IO.Compression, and every entry created with a password is encrypted with the requested method regardless of its length.

Actual behavior

Unhandled exception. System.IO.InvalidDataException: The archive entry was compressed using an unsupported compression method.
   at System.IO.Compression.ZipArchiveEntry.OpenCore(FileAccess access, ReadOnlySpan`1 password)
   at System.IO.Compression.ZipFileExtensions.ExtractToFile(ZipArchiveEntry source, String destinationFileName, Boolean overwrite, ReadOnlySpan`1 password)
   at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, Encoding entryNameEncoding, Boolean overwriteFiles, ReadOnlySpan`1 password)
   at System.IO.Compression.ZipFile.ExtractToDirectory(String sourceArchiveFileName, String destinationDirectoryName, ZipExtractionOptions options)

Regression?

No. The password support is new in .NET 11 Preview 7, so this has not worked previously.

Known Workarounds

None.

Configuration

Tested on:
.NET SDK 11.0.100-preview.7.26381.103,
runtime 11.0.0-preview.7.26381.103,
linux-x64,
window-x64

Other information

Total Commander, see this empty entry as un-ecrypted and can read w/o issue. 7-zip also sees as un-ecrypted but generates an error on read.

Activity

  1. dotnet-policy-service commented on Aug 12, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @karelz, @dotnet/area-system-io-compression
    See info in area-owners.md if you want to be subscribed.

  2. added this to the 12.0.0 milestone on Aug 13, 2026
  3. added and removed
    untriagedNew issue has not been triaged by the area owner
    on Aug 13, 2026
  4. added theissue type on Aug 13, 2026
  5. added a commit that references this issue on Aug 13, 2026
    80a1b79
  6. locked and limited conversation to collaborators on Sep 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions