Bug 40916

Summary: [System.IO.Compression] ZipArchive can create an ZipArchiveEntry that has a modified time of DateTime.MinValue
Product: [Mono] Class Libraries Reporter: Peter Spada <spadapet>
Component: GeneralAssignee: João Matos <joao.matos>
Status: VERIFIED FIXED    
Severity: normal CC: borgdylan, masafa, mono-bugs+mono, peter.collins, sachins
Priority: Normal    
Version: 4.2.0 (C6)   
Target Milestone: (C7SR1)   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Code an binaries to repro the bug

Description Peter Spada 2016-05-05 19:01:01 UTC
Created attachment 15922 [details]
Code an binaries to repro the bug

If a zip file has entries that don't have a "last write time" set, then the ZipArchiveEntry objects that are generated have a LastWriteTime of DateTime.MinValue.

While that seems like a reasonable time to use, it's different from .NET on Windows and can cause problems when the ZipArchiveEntry.LastWriteTime is used while unzipping the ZipArchive to disk. This caused a bug in NuGet: https://github.com/NuGet/Home/issues/2518

See the attached file for a project that reproduces the issue. It contains a zip file (*.nupkg) that has entries that don't have a last write time.

On .NET on Windows, for zip entries that don't have a last write time, the return value for ZipArchiveEntry.LastWriteTime is:
  1/1/1980 12:00:00 AM, Ticks=624511296000000000

On Mono on Linux, the return value for ZipArchiveEntry.LastWriteTime is:
  1/1/0001 12:00:00 AM, Ticks=0

Here is the sample code from the attachment:

namespace EntryTimeApp
{
    class Program
    {
        static void Main(string[] args)
        {
            string file = "modernhttpclient.2.4.2.nupkg";
            System.IO.Stream zipStream = System.IO.File.OpenRead(file);
            System.IO.Compression.ZipArchive zip = new System.IO.Compression.ZipArchive(zipStream, System.IO.Compression.ZipArchiveMode.Read);

            System.Console.WriteLine("Dumping entries in " + file);

            foreach (System.IO.Compression.ZipArchiveEntry entry in zip.Entries)
            {
                System.Console.WriteLine(string.Format("Name:{0}, Time:{1}, Ticks:{2}", entry.FullName, entry.LastWriteTime, entry.LastWriteTime.Ticks));
            }

            System.Console.WriteLine("Done");
        }
    }
}
Comment 1 João Matos 2016-06-17 17:31:11 UTC
https://github.com/mono/mono/pull/3184
Comment 2 Matt Ward 2016-06-22 13:49:34 UTC
*** Bug 37970 has been marked as a duplicate of this bug. ***
Comment 5 João Matos 2016-07-08 13:40:11 UTC
The build you tested does not contain the relevant commit, please test a more recent build.