ZIP files with a comment larger than 4096 throws exception #428

Open
opened 2026-01-29 22:11:51 +00:00 by claunia · 0 comments
Owner

Originally created by @elephantflea on GitHub (Dec 13, 2020).

If a ZIP file has a comment attached to the archive (not an entry) and it is over 4096 bytes it cannot be extracted as it will throw the exception:

SharpCompress.Common.ArchiveException: Could not find Zip file Directory at the end of the file. File may be corrupted.

When a call to list all entries is made. eg using LongComment.zip

using (var stream = File.OpenRead("LongComment.zip"))
using (var archive = ZipArchive.Open(stream))
{
    foreach(var entry in archive.Entries)
    {
        Console.WriteLine(entry.Key);
    }
}

I assume this is because of the constant MAX_ITERATIONS_FOR_DIRECTORY_HEADER in SeekableZipHeaderFactory.cs, but I would think there is a way to factor in the archive comment length into this logic.

Originally created by @elephantflea on GitHub (Dec 13, 2020). If a ZIP file has a comment attached to the archive (not an entry) and it is over 4096 bytes it cannot be extracted as it will throw the exception: `SharpCompress.Common.ArchiveException: Could not find Zip file Directory at the end of the file. File may be corrupted.` When a call to list all entries is made. eg using [LongComment.zip](https://github.com/adamhathcock/sharpcompress/files/5684438/LongComment.zip) ```csharp using (var stream = File.OpenRead("LongComment.zip")) using (var archive = ZipArchive.Open(stream)) { foreach(var entry in archive.Entries) { Console.WriteLine(entry.Key); } } ``` I assume this is because of the constant `MAX_ITERATIONS_FOR_DIRECTORY_HEADER` in `SeekableZipHeaderFactory.cs`, but I would think there is a way to factor in the archive comment length into this logic.
claunia added the bugup for grabs labels 2026-01-29 22:11:51 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#428