Bug 54361 - Unlike the .NET implementation, `new ZipArchive()` indirectly calls `System.Text.Encoding.GetEncoding()`
Summary: Unlike the .NET implementation, `new ZipArchive()` indirectly calls `System.T...
Status: VERIFIED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: SharpZipLib ()
Version: 4.8.0 (C9)
Hardware: PC Mac OS
: --- normal
Target Milestone: 15.2
Assignee: Bugzilla
URL:
: 37465 ()
Depends on:
Blocks: 54356
  Show dependency tree
 
Reported: 2017-04-01 01:53 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2017-04-01 02:01 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: No
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2017-04-01 01:53:32 UTC
Unlike the .NET implementation, `new ZipArchive()` indirectly calls `System.Text.Encoding.GetEncoding()`

I am filing this bug for thorough bookkeeping about the import of the .NET Core implementation of `ZipArchive` into Mono because there was a closely related existing bug report, but that report was focused on iOS only.




## Steps followed to test


1. Create a zip archive.  For example in a Terminal.app command prompt on Mac OS:

touch test
zip test.zip test


2. Paste the following lines into a .cs file:

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

namespace Program
{
    class ConsoleApp
    {
        public static void Main(string[] args)
        {
            CultureInfo.CurrentCulture = new CultureInfo("ar-AE");
            using (var archive = new ZipArchive(File.Open("test.zip", FileMode.Open),
                    ZipArchiveMode.Read))
            {
            }
        }
    }
}


3. Build and run the program.  For example in a Terminal.app command prompt:

mcs Program.cs -r:System.IO.Compression
mono --debug Program.exe




## Expected results as demonstrated by .NET Core 1.0.1 on Mac

The program runs and exits without error, even though `System.Text.Encoding.GetEncoding(720)` _does_ throw the "No data is available" in .NET Core.  So .NET Core's implementation of `ZipArchive` does not depend on calling `System.Text.Encoding.GetEncoding()` for the current culture's code page.




## Actual results with Mono 4.8.0 (mono-4.8.0-branch/e4a3cf3) on Mac

> Unhandled Exception:
> System.TypeInitializationException: The type initializer for 'SharpCompress.Common.ArchiveEncoding' threw an exception. ---> System.NotSupportedException: No data is available for encoding 720.
>   at System.Text.Encoding.GetEncoding (System.Int32 codepage) [0x001d8] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/text/encoding.cs:540 
>   at SharpCompress.Common.ArchiveEncoding..cctor () [0x00000] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/SharpCompress/Common/ArchiveEncoding.cs:24 
>    --- End of inner exception stack trace ---
>   at (wrapper managed-to-native) System.Object:__icall_wrapper_mono_generic_class_init (intptr)
>   at SharpCompress.Common.Zip.Headers.ZipFileEntry.DecodeString (System.Byte[] str) [0x00025] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/ZipFileEntry..cs:28 
>   at SharpCompress.Common.Zip.Headers.DirectoryEntryHeader.Read (System.IO.BinaryReader reader) [0x000b9] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs:32 
>   at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (System.UInt32 headerBytes, System.IO.BinaryReader reader) [0x00086] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/ZipHeaderFactory.cs:51 
>   at SharpCompress.Common.Zip.SeekableZipHeaderFactory+<ReadSeekableHeader>c__Iterator0.MoveNext () [0x00146] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs:52 
>   at SharpCompress.Archive.Zip.ZipArchive+<LoadEntries>c__Iterator0.MoveNext () [0x0013c] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/SharpCompress/Archive/Zip/ZipArchive.cs:204 
>   at SharpCompress.LazyReadOnlyCollection`1+LazyLoader[T].MoveNext () [0x0002d] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/SharpCompress/LazyReadOnlyCollection.cs:63 
>   at System.IO.Compression.ZipArchive.CreateZip (System.IO.Compression.ZipArchiveMode mode) [0x0016d] in /private/tmp/source-mono-4.8.0/bockbuild-mono-4.8.0-branch/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/System.IO.Compression/ZipArchive.cs:130
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-01 01:55:33 UTC
This is fixed by:

"[System.IO.Compression] Replaced by corefx implementation"
https://github.com/mono/mono/commit/3f9b2dfd5fd9a3efaf492558a7df71647f15ab42




## Verification status: verified fixed in the 2017-02 branch of Mono

The test program runs and exits without error on Mono 2017-02/71cc0a1.




## Additional platform verifications: verified fixed in the d15-2 branch of Xamarin.iOS

> GOOD: Xamarin.iOS 10.9.0.466 (d15-2: 0719ced1) [1]
> BAD:  Xamarin.iOS 10.8.0.175 (d15-1: a04678c2) [2]
[1] From https://jenkins.mono-project.com/view/Xamarin.MaciOS/job/xamarin-macios-builds-d15-2/2/PublishUrls/
[2] From https://jenkins.mono-project.com/view/Xamarin.MaciOS/job/xamarin-macios-builds-d15-1/57/PublishUrls/




## Additional platform verifications: verified fixed in the d15-2 branch of Xamarin.Android

> GOOD: Xamarin.Android 7.3.0.0 (d15-2: 213d2e5) [3]
> BAD:  Xamarin.Android 7.2.0.7 (d15-1: b16fb82) [4]
[3] From https://jenkins.mono-project.com/view/Xamarin.Android/job/xamarin-android-builds-d15-2/1/PublishUrls/
[4] The current Beta version as of today.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-01 02:01:03 UTC
*** Bug 37465 has been marked as a duplicate of this bug. ***