This project is read-only.


NullRereferenceException when extracting


Hey Cheeso, I am getting a NullReferenceException when extracting. Here's the stackTrace
at Ionic.Zip.ZipEntry.InternalExtract(String baseDir, Stream outstream, String password) in C:\DotNetZip\v1.9.1.5\DotNetZip\Zip Partial DLL\ZipEntry.Extract.cs:line 602 at Ionic.Zip.ZipEntry.Extract(Stream stream) in C:\DotNetZip\v1.9.1.5\DotNetZip\Zip Partial DLL\ZipEntry.Extract.cs:line 112 at MyConsole.Program.Main(String[] args) in C:\NetTiers\SourceAnywhere\NoMoreConsole\Program.cs:line 34 at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args) at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args) at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly() at System.Threading.ThreadHelper.ThreadStart_Context(Object state) at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.ThreadHelper.ThreadStart()
And here's my code.
class Program{ static void Main(string[] args) { Item1 item = DataRepository.Provider.Item1Provider.Get(new Item1Key(33170)); FileInfo1 fileInfo = DataRepository.Provider.FileInfo1Provider.Get(new FileInfo1Key(item.BiFlInfoId));//Vss.GetFileBytes(47013); using (FileStream fileStream = File.Create(item.StrItnme)) { byte[] fileBytes = fileInfo.ImEfldat; byte[] fileBytes2 = fileInfo.ImFldat; MemoryStream memStream = new MemoryStream(); memStream.Write(fileBytes, 0, fileBytes.Length); memStream.Write(fileBytes2, 0, fileBytes2.Length); memStream.Seek(0, SeekOrigin.Begin); ZipInputStream zipInStream = new ZipInputStream(memStream); ZipEntry zipEntry = zipInStream.GetNextEntry(); zipEntry.Extract(fileStream); } }}

Am I doing anything really dumb and obvious to you? I am trying to take those bytes which contain compressed data, get the first file contained in the compressed bytes and then write the decompressed file to the fileStream.

It appears that
is failing in ZipEntry.Extract.cs
Closed Jun 22, 2011 at 3:43 AM by Cheeso
This is essentially a duplicate of workitem 10355. The short answer is YES- I do see something that isn't right. The programming model for ZipInputStream assumed a streaming approach, rather than the possibility of using ZipEntry.Extract(). I've changed the library to throw a more descriptive exception when you do this. The first binary with this change will be v1.9.1.6


TheMcCann wrote Mar 9, 2011 at 10:25 PM

I looked at the source code and it seems to be a problem when working with streams. I get the problem when trying to extract an entry right after saving the zip file.

using (MemoryStream ms = new MemoryStream())
using (ZipFile zip = new ZipFile())
    zip.AddEntry("test", "my content");

    ZipEntry entry = zip["test"];
    using (MemoryStream ms2 = new MemoryStream())
        entry.Extract(ms2); // NullReferenceException thrown

On Extract, it ultimately calls ZipFile.Reset(). Since the zip was just saved, it passes the _JustSaved check and ends up calling ReadIntoInstance(). ZipFile.ReadIntoInstance(ZipFile zf) calls zf.ReadStream and then uses it without checking for null (causing exception). Notice that when ZipFile.ReadStream is called, it sees _readstream as null, but _name is ALSO null (due to using streams instead of file names). This results in a null value being returned.

Since we're using the ZipFile with only streams behind an interface, it's causing issues for us. Could this be fixed soon?


swquinn wrote Mar 22, 2011 at 2:25 AM


I've experienced the same issue--the symptoms are almost identical, except that the ZipFile in question I'm working with is simply being read (it was created by an earlier process). When instantiating the ZipFile in question, I'm reading it in as a Stream; when I go to access a ZipEntry (a file in another directory, by name, e.g. MyDir\MyFile.txt) and perform any actions on it, a NullReferenceException is thrown.

wrote Mar 22, 2011 at 2:26 AM

wrote Jun 14, 2011 at 5:02 AM

wrote Jun 22, 2011 at 3:43 AM

wrote Feb 22, 2013 at 2:43 AM

wrote May 16, 2013 at 1:31 PM