This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 40916 - [System.IO.Compression] ZipArchive can create an ZipArchiveEntry that has a modified time of DateTime.MinValue
Summary: [System.IO.Compression] ZipArchive can create an ZipArchiveEntry that has a m...
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: General (show other bugs)
Version: 4.2.0 (C6)
Hardware: PC Linux
: Normal normal
Target Milestone: (C7SR1)
Assignee: João Matos
URL:
: 37970 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-05-05 19:01 UTC by Peter Spada
Modified: 2016-07-13 22:04 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Code an binaries to repro the bug (2.65 MB, application/x-zip-compressed)
2016-05-05 19:01 UTC, Peter Spada
Details

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.

Note You need to log in before you can comment on or make changes to this bug.