Bug 30294 - System.NullReferenceException thrown when instantiating a ZipArchive with a FileStream.
Summary: System.NullReferenceException thrown when instantiating a ZipArchive with a F...
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: BCL Class Libraries ()
Version: XI 8.10
Hardware: Macintosh Mac OS
: High normal
Target Milestone: Untriaged
Assignee: João Matos
URL:
Depends on:
Blocks:
 
Reported: 2015-05-21 03:12 UTC by Adam Hartley [MSFT]
Modified: 2015-10-06 21:20 UTC (History)
12 users (show)

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


Attachments
Sample project (182.15 KB, application/zip)
2015-05-21 03:12 UTC, Adam Hartley [MSFT]
Details
Console test project (8.11 KB, application/x-gzip)
2015-05-26 13:22 UTC, Paola Villarreal
Details


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 Developer Community or GitHub 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:
RESOLVED FIXED

Description Adam Hartley [MSFT] 2015-05-21 03:12:31 UTC
Created attachment 11274 [details]
Sample project

## Overview

System.NullReferenceException thrown when instantiating a ZipArchive with a FileStream.

## Steps to reproduce

1. Download the sample project (attached).
2. Run the iOS Project.

See lines 26-28 of AppDelegate for the relevant code.

## Expected result

Should not crash.

## Actual result

System.NullReferenceException: Object reference not set to an instance of an object
at SharpCompress.Common.Zip.Headers.ZipFileEntry.DecodeString (System.Byte[] str) [0x00025] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/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 //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs:32
at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (UInt32 headerBytes, System.IO.BinaryReader reader) [0x00086] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/ZipHeaderFactory.cs:51
at SharpCompress.Common.Zip.SeekableZipHeaderFactory+<ReadSeekableHeader>c__Iterator0.MoveNext () [0x00146] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs:52
at SharpCompress.Archive.Zip.ZipArchive+<LoadEntries>c__Iterator0.MoveNext () [0x0013c] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/mcs/class/System.IO.Compression/SharpCompress/Archive/Zip/ZipArchive.cs:203
at SharpCompress.LazyReadOnlyCollection`1+LazyLoader[SharpCompress.Archive.Zip.ZipArchiveEntry].MoveNext () [0x0002d] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/mcs/class/System.IO.Compression/SharpCompress/LazyReadOnlyCollection.cs:63
at System.IO.Compression.ZipArchive.CreateZip (System.IO.Stream stream, ZipArchiveMode mode) [0x000f6] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/mcs/class/System.IO.Compression/ZipArchive.cs:117
at System.IO.Compression.ZipArchive..ctor (System.IO.Stream stream, ZipArchiveMode mode) [0x00025] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.0.267/src/mono/mcs/class/System.IO.Compression/ZipArchive.cs:62
at ZipCrash.iOS.AppDelegate.FinishedLaunching (UIKit.UIApplication app, Foundation.NSDictionary options) [0x00027] in /Users/Adam/Downloads/ZipCrash/iOS/AppDelegate.cs:28
at at (wrapper managed-to-native) UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, IntPtr principal, IntPtr delegate) [0x00005] in /Users/builder/data/lanes/1503/6481535e/source/maccore/src/UIKit/UIApplication.cs:63
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Users/builder/data/lanes/1503/6481535e/source/maccore/src/UIKit/UIApplication.cs:47
at ZipCrash.iOS.Application.Main (System.String[] args) [0x00008] in /Users/Adam/Downloads/ZipCrash/iOS/Main.cs:17

## Notes

You can work around this by manually placing “public” in front of the definition in RowController.designer.cs but it will be overwritten as it is automatically generated.
Comment 1 Abhishek 2015-05-21 07:19:24 UTC
I have tried this issue and able to reproduce the reported behavior at my end.

Steps to Reproduce:
1.Download the attached application.
2.Run the application on Device/Simulator.
3.It will give the exception "System.NullReferenceException".

Screencast: http://www.screencast.com/t/q51M2Wpnd
IDE Log: https://gist.github.com/Abhishekk360/2893db17560bc3adffcc
Exception Output: https://gist.github.com/Abhishekk360/7404c8557306bf818cc1
iOS Device Log: https://gist.github.com/Abhishekk360/804b8f22d4ba456cff34
Symbolicated log: https://gist.github.com/Abhishekk360/c1bad75956bd55e6739f

Environment Info:

=== Xamarin Studio ===

Version 5.9.2 (build 2)
Installation UUID: 93e693b0-b53d-40f4-b29c-b61ff5cbe892
Runtime:
	Mono 4.0.1 ((detached/11b5830)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010043

=== Xamarin.Android ===

Version: 5.1.2.1 (Enterprise Edition)
Android SDK: /Users/xamarin23/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
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: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Apple Developer Tools ===

Xcode 6.3 (7569)
Build 6D570

=== Xamarin.iOS ===

Version: 8.10.1.59 (Enterprise Edition)
Hash: 13d1cdc
Branch: master
Build date: 2015-05-18 22:54:57-0400

=== Xamarin.Mac ===

Version: 2.0.1.59 (Enterprise Edition)

=== Build Information ===

Release ID: 509020002
Git revision: 43735a4b905b571f69cf9428a3ea7b52aef55476
Build date: 2015-05-18 09:38:12-04
Xamarin addins: ab18ddff45f507ed74f36c2b65df9aee22e28a56

=== Operating System ===

Mac OS X 10.10.0
Darwin 800BC.local 14.0.0 Darwin Kernel Version 14.0.0
    Fri Sep 19 00:26:44 PDT 2014
    root:xnu-2782.1.97~2/RELEASE_X86_64 x86_64
Comment 2 Paola Villarreal 2015-05-26 13:22:06 UTC
Created attachment 11337 [details]
Console test project

Could not repro this issue in a console project usin mono 4.0.1

paw:Projects paw$ mono --version
Mono JIT compiler version 4.0.1 ((detached/6d5afc1 Thu May 14 09:00:20 EDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           normal
        SIGSEGV:       altstack
        Notification:  kqueue
        Architecture:  x86
        Disabled:      none
        Misc:          softdebug 
        LLVM:          yes(3.6.0svn-mono-(detached/a173357)
        GC:            sgen
Comment 3 Rodrigo Kumpera 2015-05-27 12:46:05 UTC
Hey João,

You worked on compression before, could you take a look at this one?
Comment 4 Marek Safar 2015-05-27 15:40:45 UTC
I cannot reproduce the issue with master version.

With master i get

No data is available for encoding 437. (System.NotSupportedException)
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00214] in /Developer/MonoTouch/Source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/text/encoding.cs:520 
  at SharpCompress.Common.ArchiveEncoding..cctor () [0x00000] in /Developer/MonoTouch/Source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/ArchiveEncoding.cs:24 

which is correct. Including Internationalisation codesets fixes the error.
Comment 5 Sebastien Pouliot 2015-05-27 16:20:04 UTC
That was filed against XI 8.10 (not master) and, if a regression from 8.9, will likely need to be backported to C5 SR2.

Paola should be confirmed XI 8.9 status asap. Based on that we'll see if we want to back port (and we'll need to identify the fix, maybe going back to UTF8).
Comment 6 Marek Safar 2015-05-28 03:39:54 UTC
My point was, this fails on master as well but with better exception. Including needed codesets should resolve it for earlier versions too.
Comment 7 Paola Villarreal 2015-05-28 12:45:58 UTC
Using Xamarin iOS 8.9 the NRE does not appear, instead:

System.TypeInitializationException: An exception was thrown by the type initializer for SharpCompress.Common.ArchiveEncoding ---> System.Exception: CodePage 437 not supported
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x0015d] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Text/Encoding.cs:479
  at SharpCompress.Common.ArchiveEncoding..cctor () [0x00000] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/ArchiveEncoding.cs:24
  --- End of inner exception stack trace ---
  at SharpCompress.Common.Zip.Headers.ZipFileEntry.DecodeString (System.Byte[] str) [0x00025] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/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 ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs:32
  at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (UInt32 headerBytes, System.IO.BinaryReader reader) [0x00086] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/ZipHeaderFactory.cs:51
  at SharpCompress.Common.Zip.SeekableZipHeaderFactory+<ReadSeekableHeader>c__Iterator0.MoveNext () [0x00146] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs:52
  at SharpCompress.Archive.Zip.ZipArchive+<LoadEntries>c__Iterator0.MoveNext () [0x0013c] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/SharpCompress/Archive/Zip/ZipArchive.cs:203
  at SharpCompress.LazyReadOnlyCollection`1+LazyLoader[SharpCompress.Archive.Zip.ZipArchiveEntry].MoveNext () [0x0002d] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/SharpCompress/LazyReadOnlyCollection.cs:63
  at System.IO.Compression.ZipArchive.CreateZip (System.IO.Stream stream, ZipArchiveMode mode) [0x000f6] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/ZipArchive.cs:117
  at System.IO.Compression.ZipArchive..ctor (System.IO.Stream stream, ZipArchiveMode mode) [0x00025] in ///Library/Frameworks/Xamarin.iOS.framework/Versions/8.9.1.3/src/mono/mcs/class/System.IO.Compression/ZipArchive.cs:62
  at Application.Application.Main (System.String[] args) [0x00012] in /Users/paw/Projects/Xamarin/Bugs/30294/30294/Main.cs:15


Which is the expected behaviour when the encoding is not enabled.
Comment 8 SilverBleach 2015-06-02 13:04:19 UTC
I'm not sure if is it related, but trying to instantiate ZipArchive on Android in Release mode throws the same exception reported here (oddly, it works in Debug mode):

new System.IO.Compression.ZipArchive(sourceStream, ZipArchiveMode.Read);

(In my scenario, the stream comes from assembly.GetManifestResourceStream("") and the app is a Xamarin.Forms app).

Can you please check that as well? Or should I report it as a separated bug?
Comment 9 Sebastien Pouliot 2015-10-06 15:57:20 UTC
@Brian this should be working in 9.2 (C6, see comment #4) and the exact commit was not identified for a backport to 8.10 (C5) and it's too late for this now.
Comment 11 Tim Jones 2015-10-06 20:08:07 UTC
@Sebastien thanks for the reply - what's the full version number for 9.2? I'm using what I think is the latest Xamarin.iOS (v9.0.1.29) and I'm still getting the crash.

Object reference not set to an instance of an object (System.NullReferenceException)
  at SharpCompress.Common.Zip.Headers.ZipFileEntry.DecodeString (System.Byte[] str) [0x00025] in /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/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 /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/Headers/DirectoryEntryHeader.cs:32 
  at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader (UInt32 headerBytes, System.IO.BinaryReader reader) [0x00086] in /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Ver
sions/git/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/ZipHeaderFactory.cs:51 
  at SharpCompress.Common.Zip.SeekableZipHeaderFactory+<ReadSeekableHeader>c__Iterator0.MoveNext () [0x00146] in /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.IO.Compression/SharpCompress/Common/Zip/SeekableZipHeaderFactory.cs:52 
  at SharpCompress.Archive.Zip.ZipArchive+<LoadEntries>c__Iterator0.MoveNext () [0x0013c] in /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.IO.Compression/SharpCompress/Archive/Zip/ZipArchive.cs:203 
  at SharpCompress.LazyReadOnlyCollection`1+LazyLoader[SharpCompress.Archive.Zip.ZipArchiveEntry].MoveNext () [0x0002d] in /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.IO.Compression/SharpCompress/LazyRead
OnlyCollection.cs:63 
  at System.IO.Compression.ZipArchive.CreateZip (System.IO.Stream stream, ZipArchiveMode mode) [0x000f6] in /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.IO.Compression/ZipArchive.cs:117 
  at System.IO.Compression.ZipArchive..ctor (System.IO.Stream stream, ZipArchiveMode mode, Boolean leaveOpen) [0x0002c] in /Users/builder/data/lanes/2077/1d27ac2c/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/mcs/class/System.IO.Compression/ZipArchive.cs:73 
... etc (stack trace from my application).
Comment 12 Brendan Zagaeski (Xamarin Team, assistant) 2015-10-06 20:18:42 UTC
@tim, Xamarin.iOS 9.2 is currently in Alpha [1, 2]. The latest Alpha channel build is 9.2.0.84.

[1] http://developer.xamarin.com/recipes/cross-platform/ide/change_updates_channel/

[2] https://releases.xamarin.com/alpha-release-cycle-6-5th-alpha-preview-release-candidate-0/
Comment 13 Sebastien Pouliot 2015-10-06 20:30:28 UTC
@Tim, you can get XI 9.2 from the alpha channel right now. It should be in beta soon as it hit the RC0 status earlier today.

https://blog.xamarin.com/introducing-our-first-release-candidate/

While itself recent our XI 9.0 release is based on the same mono (4.0 release) as the previous XI 8.10. The main difference, from 8.10, is the iOS 9 API support.


I just double checked the original sample myself and it works, with a single change. You need to have 'west' enabled (in iOS Build / Internationalization) as the ZIP file contains encoding that is not included by default inside applications.


I'm closing the issue with a 9.2 (C6) milestone so that our QA team can verify the fix.
Comment 14 Tim Jones 2015-10-06 21:20:24 UTC
I can confirm that with

- Xamarin.iOS 9.2.0.84, and
- enabling "west" in iOS Build / Internationalization

this now works for me. Thank you!