Malformed zip file generated #518

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

Originally created by @aboryczko on GitHub (May 26, 2022).

Hi,

I'm using salvois/LargeXlsx library for generating Excel files (which are essentialy zip files) that uses this library.
When I try to open a generated file in Excel it says that it's corrupt. If I try to open the file with any unzip tool there are no errors. When I use the built-in ZipArchive class from .NET Core everything works as expected.
I've dug a little deeper into the files generated by this library and the .NET one I see that every 16 kB I get 5 bytes inputed into the output stream.
I don't know if this is some special marker but Excel doesn't recognize it and it messes up the content for it i.e. instead of 's="0"' i have 's="0 ý€"'.

a simple way to reproduce it:

var ms = new MemoryStream();
var zw = new ZipWriter(ms, new ZipWriterOptions(compressionType: CompressionType.Deflate) { DeflateCompressionLevel = CompressionLevel.None });
var payload = new string('\n', 100000);
using (var stream = zw.WriteToStream("test.txt", new ZipWriterEntryOptions()))
using (var streamWriter = new StreamWriter(stream: stream))
{
    streamWriter.Write(value: payload);
}

sequences are at offsets: 38, 32811, 65584,98357

Linking salvois/LargeXlsx#9

Originally created by @aboryczko on GitHub (May 26, 2022). Hi, I'm using salvois/LargeXlsx library for generating Excel files (which are essentialy zip files) that uses this library. When I try to open a generated file in Excel it says that it's corrupt. If I try to open the file with any unzip tool there are no errors. When I use the built-in ZipArchive class from .NET Core everything works as expected. I've dug a little deeper into the files generated by this library and the .NET one I see that every 16 kB I get 5 bytes inputed into the output stream. I don't know if this is some special marker but Excel doesn't recognize it and it messes up the content for it i.e. instead of 's="0"' i have 's="0 ý€"'. a simple way to reproduce it: ```csharp var ms = new MemoryStream(); var zw = new ZipWriter(ms, new ZipWriterOptions(compressionType: CompressionType.Deflate) { DeflateCompressionLevel = CompressionLevel.None }); var payload = new string('\n', 100000); using (var stream = zw.WriteToStream("test.txt", new ZipWriterEntryOptions())) using (var streamWriter = new StreamWriter(stream: stream)) { streamWriter.Write(value: payload); } ``` sequences are at offsets: 38, 32811, 65584,98357 Linking salvois/LargeXlsx#9
claunia added the bugup for grabs labels 2026-01-29 22:13:12 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#518