Skip to content

ZipArchive does not indicate in any way if file length specified in central directory does not match the actual file length. #27741

@agr

Description

@agr
>dotnet --version
2.1.500-preview-009335

The following zip archive: tttt.zip has corrupted central directory entry making it report the length of the compressed file tttt.txt to be 256 bytes. All zip archivers I tried so far fail to extract that file one way or another. But ZipArchive seem to completely ignore the discrepancy:

using System;
using System.IO;
using System.IO.Compression;

namespace BrokenZipCoreTest
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var za = ZipFile.OpenRead(@"E:\dev\tttt.zip"))
            {
                var e = za.GetEntry("tttt.txt");
                Console.WriteLine("entry length: {0}", e.Length);
                using (var ms = new MemoryStream())
                {
                    using (var source = e.Open())
                    {
                        source.CopyTo(ms);
                    }

                    Console.WriteLine("actual length: {0}", ms.Length);
                }
            }
        }
    }
}

produces the following output:

entry length: 256
actual length: 39208160

No exceptions thrown.

I'm not 100% sure, but I think the library should detect it, instead of proceeding silently.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions