Skip to content

GZipStream cannot decompress multipart gzip files.  #25105

Description

@mburbea

See the following stackoverflow thread for more information.

GZipStream currently fails if you try to decompress a concatenated gzip file. The RFC does state that two gzip files can be cated together and it is also a valid gzip file. However, the current implementation can only read the first gzip stream and stops there. Here is a simple repro::

using System;
using System.IO;
using System.IO.Compression;
class Program
{
    static void Main()
    {
        using (var fs = new FileStream(Path.Combine(Environment.CurrentDirectory,"test.txt.gz"), FileMode.Create))
        {
            using(var gz = new GZipStream(fs, CompressionLevel.NoCompression, true))
            using(var sw = new StreamWriter(gz))
                sw.WriteLine("Stream 1");
                
            using(var gz = new GZipStream(fs, CompressionLevel.NoCompression, true))
            using(var sw = new StreamWriter(gz))
                sw.WriteLine("Stream 2");
            
            fs.Seek(0, SeekOrigin.Begin);
            using (var gz = new GZipStream(fs, CompressionMode.Decompress))
            using (var sr = new StreamReader(gz))
            Console.WriteLine(sr.ReadToEnd());
        }
    }
}

The expected output should be

Stream 1
Stream 2

But the actual output is just Stream 1.

If you open up "test.txt.gz" in your favorite gzip util, like 7z, you will be able to extract the file and you will see the correct output.

Metadata

Metadata

Assignees

Labels

area-System.IO.CompressionenhancementProduct code improvement that does NOT require public API changes/additions

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions