WriterFactory for Tar GZip now creates corrupt archive #243

Closed
opened 2026-01-29 22:08:55 +00:00 by claunia · 3 comments
Owner

Originally created by @Lukazoid on GitHub (Sep 29, 2017).

Originally assigned to: @adamhathcock on GitHub.

Given the following code:

using (var file = File.Open("test.tar.gz", FileMode.Create))
{
    using (var writer = WriterFactory.Open(file, ArchiveType.Tar, CompressionType.GZip))
    {
        using (var entryContents = new MemoryStream(Encoding.Default.GetBytes("Content 1")))
        {
            writer.Write("File1.txt", entryContents);
        }
        using (var entryContents = new MemoryStream(Encoding.Default.GetBytes("Content 2")))
        {
            writer.Write("File2.txt", entryContents);
        }
    }
}
using (var file = File.OpenRead("test.tar.gz"))
{
    using (var reader = ReaderFactory.Open(file))
    {
        while (reader.MoveToNextEntry())
        {
            Console.WriteLine(reader.Entry.Key);
        }
    }
}

I would expect this code to write File1.txt and then File2.txt to the console which it does for all versions of SharpCompress between 0.11.5 and 0.17.1, I am also able to extract from the created archive using 7-zip.

For versions 0.18.0, 0.18.1 and 0.18.2 the above code only outputs a single null value. I am also unable to extract the contents from the created archive using 7-zip.

It appears that this is an issue with the WriteFactory when using Tar GZip.

Originally created by @Lukazoid on GitHub (Sep 29, 2017). Originally assigned to: @adamhathcock on GitHub. Given the following code: using (var file = File.Open("test.tar.gz", FileMode.Create)) { using (var writer = WriterFactory.Open(file, ArchiveType.Tar, CompressionType.GZip)) { using (var entryContents = new MemoryStream(Encoding.Default.GetBytes("Content 1"))) { writer.Write("File1.txt", entryContents); } using (var entryContents = new MemoryStream(Encoding.Default.GetBytes("Content 2"))) { writer.Write("File2.txt", entryContents); } } } using (var file = File.OpenRead("test.tar.gz")) { using (var reader = ReaderFactory.Open(file)) { while (reader.MoveToNextEntry()) { Console.WriteLine(reader.Entry.Key); } } } I would expect this code to write `File1.txt` and then `File2.txt` to the console which it does for all versions of SharpCompress between 0.11.5 and 0.17.1, I am also able to extract from the created archive using 7-zip. For versions 0.18.0, 0.18.1 and 0.18.2 the above code only outputs a single null value. I am also unable to extract the contents from the created archive using 7-zip. It appears that this is an issue with the WriteFactory when using Tar GZip.
claunia added the bug label 2026-01-29 22:08:55 +00:00
Author
Owner

@turbolocust commented on GitHub (Apr 5, 2018):

I can confirm this. Using the following code example the produced archive is corrupt:

using (Stream stream = File.OpenWrite(@"<MYPATH>\test\out.tar.gz"))
using (var writer = WriterFactory.Open(stream, ArchiveType.Tar, CompressionType.GZip))
{
	writer.WriteAll(@"<MYPATH>\test\out", "*", SearchOption.AllDirectories);
}

using (Stream stream = File.OpenRead(@"<MYPATH>\test\out.tar.gz"))
using (var reader = ReaderFactory.Open(stream))
{
	reader.WriteAllToDirectory(@"<MYPATH>\test\out");
}

I can open it with WinRAR, but it says "Unexpected end of archive; The archive is corrupt". This does not happen when using other compression types, e.g. BZip2. Also, the extraction with the API works fine but the extracted files might be corrupt as well.

@turbolocust commented on GitHub (Apr 5, 2018): I can confirm this. Using the following code example the produced archive is corrupt: ```CSharp using (Stream stream = File.OpenWrite(@"<MYPATH>\test\out.tar.gz")) using (var writer = WriterFactory.Open(stream, ArchiveType.Tar, CompressionType.GZip)) { writer.WriteAll(@"<MYPATH>\test\out", "*", SearchOption.AllDirectories); } using (Stream stream = File.OpenRead(@"<MYPATH>\test\out.tar.gz")) using (var reader = ReaderFactory.Open(stream)) { reader.WriteAllToDirectory(@"<MYPATH>\test\out"); } ``` I can open it with WinRAR, but it says "Unexpected end of archive; The archive is corrupt". This does not happen when using other compression types, e.g. BZip2. Also, the extraction with the API works fine but the extracted files might be corrupt as well.
Author
Owner

@turbolocust commented on GitHub (May 25, 2018):

Release 0.21.x seems to have fixed this issue. I tested this with a simple text file. Under 0.20 the bug is still there but it's gone with the latest version. So this issue can be closed I guess.

@turbolocust commented on GitHub (May 25, 2018): Release 0.21.x seems to have fixed this issue. I tested this with a simple text file. Under 0.20 the bug is still there but it's gone with the latest version. So this issue can be closed I guess.
Author
Owner

@Lukazoid commented on GitHub (May 26, 2018):

Can confirm, my example seems to work with 0.21.x.

@Lukazoid commented on GitHub (May 26, 2018): Can confirm, my example seems to work with 0.21.x.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#243