Skip to content

Gzip decompress Unexpected EOF with small buffer + fix #360

@hhblaze

Description

@hhblaze

Steps to reproduce

  1. Gziped 38KB file

  2. Trying to ungzip it supplying into GZipInputStream.Read buffer with the size 10KB (smaller than gzipped array itself). Receive "Unexpected EOF".

  3. If to use buffer 50KB (more than gzipped array) - all works.

  4. It started to work with smaller buffer when the part in GZipInputStream.Read was remarked:
    image

  5. Code for decompressing

public static byte[] Decompress(this byte[] data)
{
    if (data == null)
        return null;
                
    byte[] unzipped = new byte[10000];
    int readOut = 0;
    byte[] res = null;

    try
    {
        using (Stream stream = new GZipInputStream(new MemoryStream(data)))
        {
            using (MemoryStream memory = new MemoryStream())
            {
                while((readOut = stream.Read(unzipped, 0, unzipped.Length))>0)
                    memory.Write(unzipped, 0, readOut);   

                res = memory.ToArray();
                memory.Close();
            }
            stream.Close();
        }
    }
    catch
    {   
        res = null;
    }
    return res;
}

Expected behavior

Unzip

Actual behavior

Unexpected EOF

Version of SharpZipLib

Obtained from (only keep the relevant lines)

  • Compiled from source, commit: 6f245b3

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions