Bug 34916 - GZipStream fails on iOS
Summary: GZipStream fails on iOS
Alias: None
Product: Class Libraries
Classification: Mono
Component: System ()
Version: master
Hardware: PC Mac OS
: Normal normal
Target Milestone: (C7)
Assignee: João Matos
Depends on:
Reported: 2015-10-15 16:03 UTC by Cody Beyer (MSFT)
Modified: 2016-05-18 07:13 UTC (History)
11 users (show)

Is this bug a regression?: ---
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:

Description Cody Beyer (MSFT) 2015-10-15 16:03:42 UTC
### Description 

The following sample app demonstrates an issue where attempting to decompress a zipped stream throws an exception

### Exception


### Sample


### Steps to Reproduce

1. Download sample
2. Run iOS version in Simulator
3. Click button 

### Expected Results

Stream should unzip

### Actual Results

Error is written to console

### Version

=== Xamarin Studio ===

Version 5.10 (build 811)
Installation UUID: 8ac4d87c-b82f-42fd-84d6-d10de207b0c8
	Mono 4.2.1 (explicit/804ddbc)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010060

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.0.1 (8228)
Build 7A1001

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)

SDK Tools Version: 24.4.0
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.2
Location: /Applications/Xamarin Android Player.app

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: b5396c2
Branch: master
Build date: 2015-09-30 15:22:15-0400

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 510000811
Git revision: 34cd31ea72536afab530c14d9220b286075e83cd
Build date: 2015-09-30 10:40:37-04
Xamarin addins: 8e6fccfc0c19a7e0b7b11be925f09751d827eb5c
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.11.0
Darwin Codys-MacBook-Pro.local 15.0.0 Darwin Kernel Version 15.0.0
    Wed Aug 26 16:57:32 PDT 2015
    root:xnu-3247.1.106~1/RELEASE_X86_64 x86_64
Comment 1 João Matos 2015-10-16 11:47:25 UTC
This might be a duplicate of https://bugzilla.xamarin.com/show_bug.cgi?id=34139.

Which was fixed in https://github.com/mono/mono/commit/bcb651443de098171a4e71a71d7f21a599323a4f.

Can you also replicate the same problem with a console app on the desktop?
Comment 2 Cody Beyer (MSFT) 2015-10-16 11:56:31 UTC
Console app worked fine
Comment 3 Erlend Figenschau Lund 2015-10-16 13:23:23 UTC
In summary.

Xamarin.Android the GZipStream works. 
Cody confirms it works in console app. 

In Xamarin.iOS it fails. 

Same code worked about a year ago. Don't know exact versions at that time. 

Bug is similar to https://bugzilla.xamarin.com/show_bug.cgi?id=34139 as pointed out by Matos, but not duplicate. That bug 34139 is about same error but in Xamarin.Android. The current bug 34916 is only for Xamarin.iOS - not XA where it works. 

If the bug is fixed for Xamarin.iOS as well, is it available in any alpha channel?
Do anyone know when it will be available in stable channel?
Comment 4 Sebastien Pouliot 2015-11-10 22:06:43 UTC
Xamarin.iOS is build with the zip support from mono (same source, not a fork) so it's surprising to see different results, unless different versions are used or because the test case does not work on mono itself...

$ cat z.cs
using System;
using System.IO;
using System.Text;

class Program {

static void Main () {
    var base64String = @"H4sIAAAAAAAAA6yVu27bQBBF/4VtZGHeD3ZJmhTp5C5IIUiEIcCWDEUugiD/nmEQwYRNURFAsuFwd2exZ++d+farud89davT+um5aRsC1DuEO+R7lJayRV9m5gegFqBZNB83m5fjevOzadGWUPHjaXd62XYVEy3Z04wiMTKIX0dfV0G/6FO3Pu72D/+iL916W9GbOV/X58SaS6zEKKyoGUA1eNg/nLfF2jUEBBNMtT4Wzeq567Z9HkZkE1Osf93msN/+WO32m+7zsavsh30/BUU8fy+uUCC+QIHpPQW1RAXkEGWUmSnUy2iUYSMYOGpARYViiIHcqY5kExS8rg2vY8gLGEjeYsClBVE4ORQHz3kxsEF4iS01xzBIZkgYQcYQQ7C54LQaIrxWn5+4ioT1BiRQN8Fh6MrOPjOS9Eh3M8YRJJQMZioJkUODFA8RNJ9AYuYBNyGJW5D0oi3/EpZ3dWYk5X5PN81RJGJgDATMQ5X02nFS1imVlMGvu0XwBg5/K1hY1U8tecxcNDy1/FAnG+OAQSi9PliHRaNUiuoxQYFB6T8oyAUKEu9LJ6oipbr1spyZArhWX6qbi7EOUrs7SCAoDNVgzKagMlUz+q6DQ4N8/yM=";

    byte[] byteArray = Convert.FromBase64String(base64String);
    string unZipped = null;

    using (var zippedMemoryStream = new System.IO.MemoryStream (byteArray))
    using (var gZipStream = new System.IO.Compression.GZipStream (zippedMemoryStream, System.IO.Compression.CompressionMode.Decompress))
    using (var unzippedMemStream = new System.IO.MemoryStream())
    using (var unZippedStream = new StreamReader (gZipStream, Encoding.UTF8)) {
        try {
             unZipped = unZippedStream.ReadToEnd ();
        catch (Exception ex) {
            // Fails for iOS - works for Android
            Console.WriteLine (ex.Message);

$ mcs z.cs

$ mono z.exe
Internal error (no progress possible) ReadInternal

@Cody please provide details. I got the feeling that you did not realize the `System.Diagnostics.Debug.WriteLine` would not print, by default, on the console the exception and assume that the lack of output was a success,
Comment 5 Sebastien Pouliot 2015-11-10 23:08:01 UTC

^ missing commit in the mono release branches
Comment 6 Sebastien Pouliot 2015-11-10 23:16:26 UTC
Trello card for SR1 @ https://trello.com/c/MLRS9Bz7/107-xi-34916-gzipstream-fails-on-ios

maccore/master will inherit the fix when we start using mono 4.3
Comment 7 Sebastien Pouliot 2015-11-11 21:02:49 UTC
The above fix backport was missing but it's incomplete to fix the issue (on iOS) as mono/master HEAD (6ee42d0) still fails with the same error.

poupou$ /opt/mono/bin/mono z.exe 
Internal error (no progress possible) ReadInternal

poupou$ /opt/mono/bin/mono --version
Mono JIT compiler version 4.3.0 (master/6ee42d0 Wed 11 Nov 2015 20:40:28 EST)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen
Comment 10 João Matos 2016-02-23 16:17:03 UTC
Fixed by https://github.com/mono/mono/commit/7c4d41a518aaf0370b882f9430752ebcd5544c10.

Fix has been ported to Mono 4.4 branch.