Enumerating ZipArchive.Entries collection throws NullReferenceException #339

Open
opened 2026-01-29 22:10:24 +00:00 by claunia · 0 comments
Owner

Originally created by @Metalnem on GitHub (Dec 27, 2018).

The following program throws NullReferenceException (assuming that the args[0] contains the path to the attached archive):

using System.Linq;
using SharpCompress.Archives.Zip;

namespace SharpCompress.Run
{
  public class Program
  {
    public static void Main(string[] args)
    {
      using (var zip = ZipArchive.Open(args[0]))
      {
        zip.Entries.ToList();
      }
    }
  }
}

The stack trace looks like this:

An unhandled exception of type 'System.NullReferenceException' occurred in SharpCompress.dll: 'Object reference not set to an instance of an object.'
   at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader(UInt32 headerBytes, BinaryReader reader, Boolean zip64)
   at SharpCompress.Common.Zip.SeekableZipHeaderFactory.<ReadSeekableHeader>d__3.MoveNext()
   at SharpCompress.Archives.Zip.ZipArchive.<LoadEntries>d__16.MoveNext()
   at SharpCompress.LazyReadOnlyCollection`1.LazyLoader.MoveNext()
   at SharpCompress.Utility.ForEach[T](IEnumerable`1 items, Action`1 action)
   at SharpCompress.LazyReadOnlyCollection`1.EnsureFullyLoaded()
   at SharpCompress.LazyReadOnlyCollection`1.get_Count()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at SharpCompress.Run.Program.Main(String[] args) in

Found via SharpFuzz.

Originally created by @Metalnem on GitHub (Dec 27, 2018). The following program throws **NullReferenceException** (assuming that the **args[0]** contains the path to the [attached archive](https://github.com/adamhathcock/sharpcompress/files/2712231/NullReferenceException.zip)): ```csharp using System.Linq; using SharpCompress.Archives.Zip; namespace SharpCompress.Run { public class Program { public static void Main(string[] args) { using (var zip = ZipArchive.Open(args[0])) { zip.Entries.ToList(); } } } } ``` The stack trace looks like this: ``` An unhandled exception of type 'System.NullReferenceException' occurred in SharpCompress.dll: 'Object reference not set to an instance of an object.' at SharpCompress.Common.Zip.ZipHeaderFactory.ReadHeader(UInt32 headerBytes, BinaryReader reader, Boolean zip64) at SharpCompress.Common.Zip.SeekableZipHeaderFactory.<ReadSeekableHeader>d__3.MoveNext() at SharpCompress.Archives.Zip.ZipArchive.<LoadEntries>d__16.MoveNext() at SharpCompress.LazyReadOnlyCollection`1.LazyLoader.MoveNext() at SharpCompress.Utility.ForEach[T](IEnumerable`1 items, Action`1 action) at SharpCompress.LazyReadOnlyCollection`1.EnsureFullyLoaded() at SharpCompress.LazyReadOnlyCollection`1.get_Count() at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection) at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source) at SharpCompress.Run.Program.Main(String[] args) in ``` Found via [SharpFuzz](https://github.com/Metalnem/sharpfuzz).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#339